Skip to content

Commit

Permalink
Fix lazy option on withInitAction
Browse files Browse the repository at this point in the history
Prevent 'not prepared' error on lazy components

Move initComponent call for lazy components to componentDidMount
  • Loading branch information
flut1 committed May 13, 2017
1 parent 1e955bc commit cf442ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/actions/initComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default (
componentId,
initProps,
initAction,
options: { onError, getInitState, initSelf },
options: { onError, getInitState, initSelf, lazy },
} = Component.initConfig;

const initState = getInitState(getState());
Expand All @@ -52,7 +52,7 @@ export default (
const { mode, prepared } = initState;

if (
((mode === MODE_INIT_SELF) && (initSelf !== INIT_SELF_NEVER)) ||
(((mode === MODE_INIT_SELF) || lazy) && (initSelf !== INIT_SELF_NEVER)) ||
(isPrepare && (typeof prepared[prepareKey] === 'undefined'))
) {
const initPropsObj = propNameValuesToObject(initProps, initValues);
Expand Down
10 changes: 9 additions & 1 deletion src/withInitAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ export default (p1, p2, p3) => {
componentWillMount() {
const { initValues, prepareKey } = this.props.__componentInitState;

if (initSelf !== INIT_SELF_NEVER) {
if (initSelf !== INIT_SELF_NEVER && !lazy) {
this.props.__initComponent(initValues, prepareKey).catch(this.handleInitError);
}
}

componentDidMount() {
if (lazy) {
const { initValues, prepareKey } = this.props.__componentInitState;

this.props.__initComponent(initValues, prepareKey).catch(this.handleInitError);
}
}
Expand Down

0 comments on commit cf442ba

Please sign in to comment.