electrum-store
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -223,2 +223,12 @@ 'use strict'; | ||
keys.forEach(key => { | ||
if (key === '$apply') { | ||
// Do not store meta-properties | ||
return; | ||
} | ||
if (key === 'array') { | ||
// Process the array as if it had been passed in at the top | ||
// level of this function. | ||
this.applyChanges(id, obj[key], defaultKey); | ||
return; | ||
} | ||
this.select(id).set(key, obj[key]); | ||
@@ -225,0 +235,0 @@ }); |
{ | ||
"name": "electrum-store", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "Electrum store provides a store implementation tailored for Electrum.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -235,4 +235,31 @@ # Electrum Store | ||
expect (store.find ('root.12').get ('name')).to.equal ('bar'); | ||
``` | ||
``` | ||
## Special `array` property | ||
When applying specially tagged objects (using `$apply: 'props'`), | ||
a property `array` will be treated as if it had been set at the | ||
containing level: | ||
```javascript | ||
const store = Store.create (); | ||
const changes = { | ||
$apply: 'props', | ||
name: 'John', | ||
age: 42, | ||
array: [ | ||
{offset: 1, id: 'x', value: {x: 10}}, | ||
{offset: 2, id: 'y', value: {y: 20}} | ||
] | ||
}; | ||
// Properties name/age will be set on root node directly, and | ||
// the array will be applied on root too. | ||
store.applyChanges ('root', changes); | ||
expect (store.find ('root').get ('name')).to.equal ('John'); | ||
expect (store.find ('root').get ('age')).to.equal (42); | ||
expect (store.find ('root.1.x').get ()).to.equal (10); | ||
expect (store.find ('root.2.y').get ()).to.equal (20); | ||
``` | ||
# State | ||
@@ -239,0 +266,0 @@ |
@@ -108,2 +108,23 @@ 'use strict'; | ||
it ('interprets array property', () => { | ||
const store = Store.create (); | ||
const info = { | ||
$apply: 'props', | ||
name: 'foo', | ||
array: [ | ||
{offset: 10, id: 'x', value: {year: 2016, name: 'foo'}}, | ||
{offset: 12, id: 'y', value: {$apply: 'props', year: 1984, name: 'bar'}} | ||
] | ||
}; | ||
// Properties year/name will be set on node 12 directly | ||
store.applyChanges ('root', info); | ||
expect (store.find ('root').get ('name')).to.equal ('foo'); | ||
expect (store.find ('root.10.year').get ()).to.equal (2016); | ||
expect (store.find ('root.10.name').get ()).to.equal ('foo'); | ||
expect (store.find ('root.12.year')).to.not.exist (); | ||
expect (store.find ('root.12.name')).to.not.exist (); | ||
expect (store.find ('root.12').get ('year')).to.equal (1984); | ||
expect (store.find ('root.12').get ('name')).to.equal ('bar'); | ||
}); | ||
it ('removes entries in array', () => { | ||
@@ -167,3 +188,24 @@ const store = Store.create (); | ||
}); | ||
it ('example (3) from README works', () => { | ||
const store = Store.create (); | ||
const changes = { | ||
$apply: 'props', | ||
name: 'John', | ||
age: 42, | ||
array: [ | ||
{offset: 1, id: 'x', value: {x: 10}}, | ||
{offset: 2, id: 'y', value: {y: 20}} | ||
] | ||
}; | ||
// Properties name/age will be set on root node directly, and | ||
// the array will be applied on root too. | ||
store.applyChanges ('root', changes); | ||
expect (store.find ('root').get ('name')).to.equal ('John'); | ||
expect (store.find ('root').get ('age')).to.equal (42); | ||
expect (store.find ('root.1.x').get ()).to.equal (10); | ||
expect (store.find ('root.2.y').get ()).to.equal (20); | ||
}); | ||
}); | ||
}); |
@@ -212,2 +212,12 @@ 'use strict'; | ||
keys.forEach (key => { | ||
if (key === '$apply') { | ||
// Do not store meta-properties | ||
return; | ||
} | ||
if (key === 'array') { | ||
// Process the array as if it had been passed in at the top | ||
// level of this function. | ||
this.applyChanges (id, obj[key], defaultKey); | ||
return; | ||
} | ||
this | ||
@@ -214,0 +224,0 @@ .select (id) |
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
113351
2497
451