state-tree
Advanced tools
Comparing version 0.1.16 to 0.1.17
{ | ||
"name": "state-tree", | ||
"version": "0.1.16", | ||
"version": "0.1.17", | ||
"description": "A state tree that handles reference updates and lets you flush a description of changes", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
var subscribers = []; | ||
function getByPath(path, state) { | ||
return path.reduce(function (currentPath, key) { | ||
function getByPath(path, state, forcePath) { | ||
return path.reduce(function (currentPath, key, index) { | ||
if (forcePath && currentPath[key] === undefined) { | ||
var newBranch = {}; | ||
Object.defineProperty(newBranch, '.referencePaths', { | ||
writable: true, | ||
configurable: true, | ||
value: [path.slice().splice(0, index + 1)] | ||
}); | ||
currentPath[key] = newBranch; | ||
} | ||
return currentPath[key]; | ||
@@ -131,3 +141,3 @@ }, state); | ||
var key = pathArray.pop(); | ||
var host = getByPath(pathArray, state); | ||
var host = getByPath(pathArray, state, true); | ||
cleanReferences(host[key], state, originalPath); | ||
@@ -210,3 +220,3 @@ host[key] = setReferences(value, pathArray.concat(key)); | ||
var key = pathArray.pop(); | ||
var host = getByPath(pathArray, state); | ||
var host = getByPath(pathArray, state, true); | ||
var child = host[key] || host; | ||
@@ -213,0 +223,0 @@ Object.keys(value).forEach(function (mergeKey) { |
@@ -58,1 +58,10 @@ var Lib = require('../src'); | ||
}; | ||
exports['should be able to set paths that does not exist'] = function (test) { | ||
var lib = Lib({}); | ||
lib.set('foo.bar.test', 'bar2'); | ||
test.deepEqual(lib.get(), {foo: { bar: { test: 'bar2' } } }); | ||
test.deepEqual(lib.get('foo')['.referencePaths'], [['foo']]); | ||
test.deepEqual(lib.get('foo.bar')['.referencePaths'], [['foo', 'bar']]); | ||
test.done(); | ||
}; |
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
37826
935