Skip to content

Commit d536959

Browse files
committed
fix(change): change onAfter/beforeChange to onBefore/After
1 parent 4176dc9 commit d536959

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ webpack.config.js
1818
.eslintignore
1919
.flowconfig
2020
*.png
21+
yarn.lock

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ The first argument can be a function that returns a promise, a promise itself, o
156156

157157
- `onError` is a callback called if async imports fail. It does not apply to sync requires.
158158

159-
- `onLoad` is a callback function that receives the *entire* module. It allows you to export and put to use things other than your `default` component export, like reducers, sagas, etc. E.g: `onLoad: module => store.replaceReducer({ ...otherReducers, foo: module.fooReducer })`. It's fired directly before the component is rendered so you can setup any reducers/etc it depends on. Unlike `onAfterChange`, it's only fired the first time the module is received. *Also note*: it will fire on the server, so do `if (!isServer)` if you have to.
159+
- `onLoad` is a callback function that receives the *entire* module. It allows you to export and put to use things other than your `default` component export, like reducers, sagas, etc. E.g: `onLoad: module => store.replaceReducer({ ...otherReducers, foo: module.fooReducer })`. It's fired directly before the component is rendered so you can setup any reducers/etc it depends on. Unlike `onAfter`, it's only fired the first time the module is received. *Also note*: it will fire on the server, so do `if (!isServer)` if you have to.
160160

161161
- `minDelay` is essentially the minimum amount of time the `loading` component will always show for. It's good for enforcing silky smooth animations, such as during a 500ms sliding transition. It insures the re-render won't happen until the animation is complete. It's often a good idea to set this to something like 300ms even if you don't have a transition, just so the loading spinner shows for an appropriate amount of time without jank.
162162

src/flowTypes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ export type Ids = Array<string>
9191
export type State = { error?: any, Component?: ?any }
9292

9393
type Info = { isMount: boolean, isSync: boolean, isServer: boolean }
94-
type OnBeforeChange = Info => void
95-
type OnAfterChange = (Info, any) => void
94+
type OnBefore = Info => void
95+
type OnAfter = (Info, any) => void
9696

9797
export type Props = {
9898
error?: ?any,
9999
isLoading?: ?boolean,
100-
onBeforeChange?: OnBeforeChange,
101-
onAfterChange?: OnAfterChange
100+
OnBefore?: OnBefore,
101+
OnAfter?: OnAfter
102102
}
103103

104104
export type GenericComponent<Props> =

src/index.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ export default function universal<Props: Props>(
155155
isSync: boolean,
156156
isServer?: boolean = false
157157
) {
158-
if (this.props.onBeforeChange) {
159-
const onBeforeChange = this.props.onBeforeChange
158+
if (typeof this.props.onBefore === 'function') {
159+
const onBefore = this.props.onBefore
160160
const info = { isMount, isSync, isServer }
161-
onBeforeChange(info)
161+
onBefore(info)
162162
}
163163
}
164164

@@ -168,14 +168,16 @@ export default function universal<Props: Props>(
168168
isSync: boolean,
169169
isServer: boolean
170170
) {
171-
if (state.Component && !state.error) {
172-
hoist(UniversalComponent, state.Component, { preload: true })
171+
const { Component, error } = state
172+
173+
if (Component && state.error) {
174+
hoist(UniversalComponent, Component, { preload: true })
173175
}
174176

175-
if (state.Component && !state.error && this.props.onAfterChange) {
176-
const onAfterChange = this.props.onAfterChange
177+
if (Component && !error && typeof this.props.onAfter === 'function') {
178+
const onAfter = this.props.onAfter
177179
const info = { isMount, isSync, isServer }
178-
this.setState(state, () => onAfterChange(info, state.Component))
180+
this.setState(state, () => onAfter(info, Component))
179181
return
180182
}
181183

0 commit comments

Comments
 (0)