Last active
September 4, 2017 18:32
-
-
Save arackaf/f43758c1421fd052865690c72248f27f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const combineLazyReducers = (reducers, initialState) => { | |
| initialState = initialState || {}; | |
| let handler = { | |
| ownKeys(target){ | |
| return Array.from(new Set([...Reflect.ownKeys(target), ...Reflect.ownKeys(initialState)])); | |
| }, | |
| get(target, key){ | |
| return target[key] || (state => state === undefined ? null : state); | |
| }, | |
| getOwnPropertyDescriptor(target, key){ | |
| return Reflect.getOwnPropertyDescriptor(target, key) || Reflect.getOwnPropertyDescriptor(initialState, key); | |
| } | |
| }; | |
| return combineReducers(new Proxy(reducers, handler)); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment