Skip to content

Instantly share code, notes, and snippets.

@arackaf
Last active September 4, 2017 18:32
Show Gist options
  • Select an option

  • Save arackaf/f43758c1421fd052865690c72248f27f to your computer and use it in GitHub Desktop.

Select an option

Save arackaf/f43758c1421fd052865690c72248f27f to your computer and use it in GitHub Desktop.
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