create-reducer-tree
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -31,15 +31,18 @@ "use strict"; | ||
exports.fetchActionsForTree = fetchActionsForTree; | ||
var states = []; | ||
function generateInitialState(tree) { | ||
function removeActionsAndReducers(state) { | ||
for (var i in state) { | ||
if (i === "actions" || i === "reducer" || i === "initialState") { | ||
delete state[i]; | ||
function handleStateChunk(state) { | ||
var newState = {}; | ||
var keys = fetchKeysInItem(state); | ||
keys.forEach(function (key) { | ||
if (key !== "initialState" && key !== "actions" && key !== "reducer") { | ||
newState[key] = handleStateChunk(state[key]); | ||
} | ||
removeActionsAndReducers(state[i]); | ||
} | ||
if (key === "initialState") { | ||
Object.assign(newState, state[key]); | ||
} | ||
}); | ||
return newState; | ||
} | ||
var state = JSON.parse(JSON.stringify(tree)); | ||
removeActionsAndReducers(state); | ||
states.push(state); | ||
var newState = handleStateChunk(state); | ||
return state; | ||
@@ -52,3 +55,2 @@ } | ||
var initialState = reducerTree.initialState || generateInitialState(reducerTree); | ||
console.log(initialState); | ||
return function (state, action) { | ||
@@ -55,0 +57,0 @@ if (state === void 0) { state = clone(initialState); } |
{ | ||
"name": "create-reducer-tree", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A tool to create a redux reducer composition tree", | ||
@@ -5,0 +5,0 @@ "main": "dist/create-reducer-tree.js", |
@@ -31,16 +31,19 @@ declare function require(string: string): any; | ||
} | ||
let states = []; | ||
export function generateInitialState(tree: any): any { | ||
function removeActionsAndReducers(state) { | ||
for (var i in state) { | ||
if (i === "actions" || i === "reducer" || i === "initialState") { | ||
delete state[i]; | ||
function handleStateChunk(state: any) { | ||
let newState = {}; | ||
let keys = fetchKeysInItem(state); | ||
keys.forEach(key => { | ||
if (key !== "initialState" && key !== "actions" && key !== "reducer") { | ||
newState[key] = handleStateChunk(state[key]); | ||
} | ||
removeActionsAndReducers(state[i]); | ||
} | ||
if (key === "initialState") { | ||
Object.assign(newState, state[key]); | ||
} | ||
}); | ||
return newState; | ||
} | ||
let state = JSON.parse(JSON.stringify(tree)); | ||
removeActionsAndReducers(state); | ||
states.push(state); | ||
let newState = handleStateChunk(state); | ||
return state; | ||
@@ -53,3 +56,2 @@ } | ||
let initialState = reducerTree.initialState || generateInitialState(reducerTree); | ||
console.log(initialState) | ||
return function (state: any = clone(initialState), action: {type: string, payload: any}) { | ||
@@ -56,0 +58,0 @@ if (actions.indexOf(action.type) > -1) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31277
556