Skip to content

Commit

Permalink
WIP2
Browse files Browse the repository at this point in the history
  • Loading branch information
overlookmotel committed Aug 17, 2018
1 parent 33a951b commit b484dac
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var LoadableDataComponent = function (_React$Component) {
value: function _load() {
var _this2 = this;

console.log('loading!');
//console.log('loading!');

this.setState({ loading: true });

Expand Down
23 changes: 21 additions & 2 deletions src/example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,32 @@ const LoadableData = require('../');

// Exports

function LoadyInner(props) {
return <div>
<h2>LoadyInner</h2>
<p>props: {inspect(props)}</p>
</div>;
}

const LoadyInnerWithData = LoadableData({ // jshint ignore:line
loader: props => {
//console.log('loader inner called with:', {props});
return Promise.resolve(Object.assign({d: 999}, props))
},
component: LoadyInner,
Loading: () => <div>Loading...</div>
});

function Loady(props) {
return <p>{inspect(props)}</p>;
return <div>
<h2>Loady</h2>
<LoadyInnerWithData {...props}/>
</div>;
}

const LoadyWithData = LoadableData({ // jshint ignore:line
loader: props => {
console.log('loader called with:', {props});
//console.log('loader called with:', {props});
return Promise.resolve(Object.assign({c: 789}, props))
},
component: Loady,
Expand Down
13 changes: 8 additions & 5 deletions src/example/ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ const LoadableData = require('../');
const App = require('./app');

// Run
render(App).then(res => {
renderComponent(App).then(res => {
console.log('done!');
console.log('data:', res.data);
console.log('html:', res.html);
});

function render(Component, props) {
function renderComponent(Component, props) {
const data = [], promises = [];

console.log('creating element');
Expand All @@ -26,6 +26,10 @@ function render(Component, props) {
</LoadableData.ServerProvider>
);

return renderElement(element, data, promises).then(html => ({html, data}));
}

function renderElement(element, data, promises) {
return next(true);

function next(first) {
Expand All @@ -36,9 +40,8 @@ function render(Component, props) {

if (promises.length == 0) {
console.log('complete:', {data, promises});
const res = {html, data};
if (first) return Promise.resolve(res);
return res;
if (first) return Promise.resolve(html);
return html;
}

return Promise.all(promises).then(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LoadableDataComponent extends React.Component {
}

_load() {
console.log('loading!');
//console.log('loading!');

this.setState({loading: true});

Expand Down

0 comments on commit b484dac

Please sign in to comment.