Skip to content

Commit

Permalink
feat(createContextHandler): passing undefined or null to the handler …
Browse files Browse the repository at this point in the history
…function will reset the data fo

affects: @tao.js/react

now provides a way to remove data from the context
  • Loading branch information
eudaimos committed May 17, 2019
1 parent 09bd89f commit 78aee3f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions packages/react-tao/src/createContextHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import { normalizeAC, cleanInput } from './helpers';
import { Context } from './Provider';

function cleanState(previousState, newState) {
return Object.keys(previousState)
.concat(Object.keys(newState))
.reduce((rv, key) => {
rv[key] = newState[key];
const keys = Object.keys(previousState);
if (newState == null) {
return keys.reduce((rv, key) => {
rv[key] = void 0;
return rv;
}, {});
}
keys.push(...Object.keys(newState));
return keys.reduce((rv, key) => {
rv[key] = newState[key];
return rv;
}, {});
}

export default function createContextHandler(tao, handler, defaultValue) {
Expand Down

0 comments on commit 78aee3f

Please sign in to comment.