Async observable prefetcher for react components
npm install smallorange-react-async-prefetcher
export class Child extends React.Component {
static asyncs = {
childAsync: Observable.of('child async'),
childAsync2: Observable.of('child async II'),
notAsync: 'notAsync'
};
render() {
const {
asyncs = {}
} = this.props;
return (
export class App extends React.Component {
static asyncs = {
parentAsync: Observable.of('parent async'),
parentAsync2: Observable.of('parent async II'),
notAsync: 'notAsync'
};
static dependencies = {
child: {
component: 'Child'
},
children: [{
component: 'Child'
}, {
component: 'Child'
}]
};
render() {
const {
asyncs = {},
dependencies = {}
} = this.props;
const Child = dependencies.child || null;
return (
{_.map(asyncs, (value, key) => (
))}
{Child ?
{_.map(dependencies.children, (Component, key) => (
Component ?
))}
);
}
}
import * as components from 'components';
const descriptor = {
app: {
component: 'App' || components.App
},
child: {
component: 'Child' || components.Child
}
};
const prefetcher = new Prefetcher(components / just provide this if you intend to lookup components via strings, in descriptor /);
prefetcher.run(descriptor.app)
.subscribe(response => {
const Component = response;
renderToStaticMarkup(
});
// Or via container
const ContainerApp = container(component.App);
renderToStaticMarkup(