bene@theodo.co.uk
Ben Ellerby
First React-Native London Meetup July 28, 2016
UI Render
Business Logic
Configuration
UI Render
UI Render
Visual primitives for the component age.
const Button = styled.button`
border-radius: 3px;
padding: 0.25em 1em;
margin: 0 1em;
background: transparent;
color: palevioletred;
border: 2px solid palevioletred;
`;
Really helpful in React, but not always chosen for React-Native project
(I'm a fan, even if tagged template literals get some getting used to)
UI Render
UI Render
Builds off React-Primitives
"
https://github.com/lelandrichardson/react-primitives
UI Render
UI Render
Sketch
React
React-Native
UI Render
Note that this is an experimental release: There might be bugs and there also isn’t a massive amount of documentation
UI Render
I believe that Web, Mobile Web and Native Application environments all require a specific design and user experience.
UI Render
Business Logic
Configuration
API / Formatting
API / Formatting
API calls, authentication and formatting of request & response data.
Configuration
Config files, translation files and most constant data is not render environment specific.
If I update a translation on my app, it's likely I want that changed rolled out on my site too.
Business Logic
Again environment independent.
If a user can only add 20 items to their basket, this rule will hold true in web and native equally.
UI Render
Business Logic
Configuration
API / Formatting
UI
Render Environment Independent
Our whole redux store is shared
Our Apollo queries are shared
A higher-order component (HOC) is an advanced technique in React for reusing component logic. HOCs are not part of the React API, per se. They are a pattern that emerges from React’s compositional nature.
// @flow
import React from 'react';
import { Query } from 'react-apollo';
const withData = (query, backupData) => WrappedComponent => {
return props => (
<Query query={query} pollInterval={10000}>
{injectedProps => <WrappedComponent backupData={backupData} {...injectedProps} {...props} />};
</Query>
);
};
export default withData;
All Apollo query HOCs are shared:
e.g. withSearchResults, withBasket, withProducts
MadeNative
MadeWeb
MadeShared
MadeShared
/hoc
/queries
/conditional-render...
/dataFormatting
/config
/translations /colours
/types /api
/redux
/actions
/reducers
/selectors
import React from 'react';
import { connect } from 'react-redux';
import { compose, branch, renderComponent } from 'recompose';
import { getUserPermissionSets } from 'redux/login/login.selectors';
const mapStateToProps = state => ({
userPermissions: getUserPermissionSets(state),
});
export default (permission, UnauthorisedComponent) =>
compose(
connect(mapStateToProps),
branch(
({ userPermissions }) => !userPermissions.includes(permission),
renderComponent(UnauthorisedComponent),
),
);
renderIfAuthorised(permissionsMap.CREATE_ROLE)(
RoleCreationPageWrapper,
);
MadeShared
var path = require('path');
module.exports = {
entry: './shared/index.js',
output: {
path: path.resolve(__dirname),
filename: 'index.js',
libraryTarget: 'commonjs2',
},
module: {
rules: [
{
test: /\.js$/,
include: path.resolve(__dirname, 'shared'),
exclude: /(node_modules|bower_components|build)\//,
use: {
loader: 'babel-loader',
options: {
presets: ['env'],
},
},
},
],
},
externals: {
react: 'commonjs react',
'react-apollo': 'commonjs react-apollo',
},
};
Webpack config to transpile to commonjs2
...
"dependencies": {
...
"made-shared":
"git+https://AUTHTOKEN:x-oauth-basic@github.com/REPO/made-shared.git#master-1.05",
...
...
MadeWeb / MadeNative
...
"dependencies": {
...
"made-shared":
"git+https://AUTHTOKEN:x-oauth-basic@github.com/REPO/made-shared.git#master-1.05",
...
...
MadeWeb / MadeNative
yarn build
git tag master-1.06
git push --tags
git merge
Update package.json
MadeWeb / MadeNative
...
"dependencies": {
...
"made-shared": "1.05",
...
...
MadeNative
We use AppCenter as our App CI
It needs to pull the shared library, but it's private...
MadeNative
Me: Hello, we’re wanting to have a shared library used in our project. This would require an npm install from a private NPM repo (through package cloud). What is the best practice for adding a private npm access on the AppCenter CI?
MadeNative
Microsoft: We currently only support cloud git repositories hosted on VSTS, Bitbucket and GitHub. Support for private repos is not available yet but we are building new features all the time, you can keep an eye out on our roadmap for upcoming features.
MadeNative
bene@theodo.co.uk
ben@ellerby.tech
https://www.linkedin.com/in/benjaminellerby/