compose-state
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -1,1 +0,1 @@ | ||
"use strict";var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};Object.defineProperty(exports,"__esModule",{value:!0});function _toConsumableArray(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}var composeStateFactory=function(a){return function(){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];return c.map(function(a){return a instanceof Function?a:function(){return a}}).reduceRight(function(b,c){return function(){for(var d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];var g=e[a],h=b.apply(void 0,e),i=c.apply(void 0,_toConsumableArray(e.slice(0,a)).concat([_extends({},g,h)],_toConsumableArray(e.slice(a+1))));return g||h||i?_extends({},g,h,i):null}},function(){return null})}},composeState=exports.composeState=composeStateFactory(0),composeDerivedStateFromProps=exports.composeDerivedStateFromProps=composeStateFactory(1);exports.default=composeState; | ||
"use strict";var _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a};Object.defineProperty(exports,"__esModule",{value:!0});function _toConsumableArray(a){if(Array.isArray(a)){for(var b=0,c=Array(a.length);b<a.length;b++)c[b]=a[b];return c}return Array.from(a)}var composeStateFactory=function(a){return function(){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];return c.map(function(a){return a instanceof Function?a:function(){return a}}).reduceRight(function(b,c){return function(){for(var d=arguments.length,e=Array(d),f=0;f<d;f++)e[f]=arguments[f];var g=b.apply(void 0,e),h=c.apply(void 0,_toConsumableArray(e.slice(0,a)).concat([_extends({},e[a],g)],_toConsumableArray(e.slice(a+1))));return h?_extends({},e[a],g,h):null}},function(){return null})}},composeState=exports.composeState=composeStateFactory(0),composeDerivedStateFromProps=exports.composeDerivedStateFromProps=composeStateFactory(1);exports.default=composeState; |
@@ -6,12 +6,11 @@ const composeStateFactory = stateIndex => (...updaters) => | ||
(accumulator, current) => (...args) => { | ||
const prevState = args[stateIndex]; | ||
const accumulatedState = accumulator(...args); | ||
const currentState = current( | ||
...args.slice(0, stateIndex), | ||
{ ...prevState, ...accumulatedState }, | ||
{ ...args[stateIndex], ...accumulatedState }, | ||
...args.slice(stateIndex + 1), | ||
); | ||
return prevState || accumulatedState || currentState | ||
? { ...prevState, ...accumulatedState, ...currentState } | ||
return currentState | ||
? { ...args[stateIndex], ...accumulatedState, ...currentState } | ||
: null; | ||
@@ -18,0 +17,0 @@ }, |
{ | ||
"name": "compose-state", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "compose setState updaters", | ||
@@ -5,0 +5,0 @@ "main": "dist.js", |
@@ -217,2 +217,8 @@ import React, { Component } from "react"; | ||
}); | ||
setState({ | ||
name: "null updaters, default state", | ||
expected: { value: 1 }, | ||
updaters: [() => null], | ||
state: { value: 1 }, | ||
}); | ||
deriveState({ name: "no value", expected: {} }); | ||
@@ -219,0 +225,0 @@ deriveState({ |
9620
276