-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(@wxa/redux): support reducer registry for lazy load model in sub…
…package
- Loading branch information
Showing
3 changed files
with
165 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// http://nicolasgallagher.com/redux-modules-and-code-splitting/ | ||
// learn from nicolas | ||
|
||
export class ReducerRegistry { | ||
constructor() { | ||
this._emitChange = null; | ||
this._reducers = {}; | ||
} | ||
|
||
getReducers() { | ||
return { ...this._reducers }; | ||
} | ||
|
||
register(name, reducer) { | ||
this._reducers = { ...this._reducers, [name]: reducer }; | ||
if (this._emitChange) { | ||
this._emitChange(this.getReducers()); | ||
} | ||
} | ||
|
||
setChangeListener(listener) { | ||
this._emitChange = listener; | ||
} | ||
} | ||
|
||
const reducerRegistry = new ReducerRegistry(); | ||
export default reducerRegistry; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters