bene@theodo.co.uk
Ben Ellerby
UI Render
Business Logic
Configuration
API / Formatting
<div> != <View>
<ul> != <FlatList>
UI Render
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;
`;
UI Render
UI Render
Builds off React-Primitives
"Primitive React Interfaces Across Targets"
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
UI Render
I believe that Web, Mobile Web and Native Application environments all require a specific design and user experience.
It’s worth noting that we’re not chasing “write once, run anywhere.” Different platforms have different looks, feels, and capabilities, and as such, we should still be developing discrete apps for each platform, but the same set of engineers should be able to build applications for whatever platform they choose, without needing to learn a fundamentally different set of technologies for each. We call this approach “learn once, write anywhere.”
UI Render
Business Logic
Configuration
API / Formatting
API / Formatting
API calls, authentication and formatting of request & response data.
If we make a POST to a REST API on web, it's the same POST on native.
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.
Configuration
Shared Config Object
Native Config Object
{
....,
foo: "bar",
}
Web Config Object
Configuration
Again environment independent.
If a user can only add 20 items to their basket, this rule will hold true in web and native equally.
Business Logic
UI Render
Business Logic
Configuration
API / Formatting
UI
Render Environment Independent
Our whole redux store is shared
Our Apollo queries are shared
HigerOrderComponent
WrappedComponent
props: { foo: "bar" }
props.foo //bar
import React from 'react';
import { Query } from 'react-apollo';
const withData = (query) => WrappedComponent => {
return props => (
<Query query={query}>
{injectedProps =>
<WrappedComponent {...injectedProps} {...props} />};
</Query>
);
};
export default withData;
All Apollo query HOCs are shared:
e.g. withSearchResults, withBasket, withProducts
renderIfAuthorised
import React from 'react';
import { connect } from 'react-redux';
import { compose, branch, renderComponent } from 'recompose';
import { getUserPermissionSets } from 'login.selectors';
const mapStateToProps = state => ({
userPermissions: getUserPermissionSets(state),
});
export default (permission, UnauthorisedComponent) =>
compose(
connect(mapStateToProps),
branch(
({ userPermissions }) =>
!userPermissions.includes(permission),
renderComponent(UnauthorisedComponent),
),
);
MadeNative
MadeWeb
MadeShared
MadeShared
/hoc
/queries
/conditional-rendering
/config
/translations /colours
/types /api
/redux
/actions
/reducers
/selectors /sagas
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
MadeShared
...
"dependencies": {
...
"made-shared":
"git+https://AUTHTOKEN:x-oauth-basic@github.com/REPO/made-shared.git#master-1.05",
...
...
...
"dependencies": {
...
"made-shared": "1.5.1",
...
...
4 Weeks with one change to the shared library!
MadeNative
We use AppCenter as our App CI
It needs to pull the shared library, but it's private...
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
MadeNative
ben@ellerby.tech
https://www.linkedin.com/in/benjaminellerby/