electrum-store
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -177,2 +177,7 @@ 'use strict'; | ||
}, { | ||
key: 'shouldUpdate', | ||
value: function shouldUpdate(generation) { | ||
return !generation || generation >= this.generation; | ||
} | ||
}, { | ||
key: 'id', | ||
@@ -179,0 +184,0 @@ get: function () { |
{ | ||
"name": "electrum-store", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "Electrum store provides a store implementation tailored for Electrum.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -103,2 +103,23 @@ # Electrum Store | ||
## Check the generation | ||
State has an intrinsic _generation_ which can be retrieved with the | ||
`generation` property. As soon as a state is attached to a store, its | ||
generation will be a strictly positive integer (1...n). | ||
The helper method `shouldUpdate()` returns `true` when the provided | ||
generation is compatible with the state's own generation (i.e. equal | ||
or more recent to the state generation). | ||
```javascript | ||
const store = Store.create (); | ||
store.select ('a'); | ||
store.select ('a.b'); | ||
const state = store.select ('a.b'); | ||
expect (state.generation).to.equal (2); | ||
expect (state.shouldUpdate (1)).to.be.false (); // provided gen=1 older than state.generation | ||
expect (state.shouldUpdate (2)).to.be.true (); | ||
expect (state.shouldUpdate (3)).to.be.true (); | ||
``` | ||
# State | ||
@@ -105,0 +126,0 @@ |
@@ -306,2 +306,23 @@ 'use strict'; | ||
}); | ||
describe ('shouldUpdate', () => { | ||
it ('returns true for unknown generations', () => { | ||
const store = Store.create (); | ||
store.select ('a'); | ||
const state = store.select ('a.b.c'); | ||
expect (state.generation).to.equal (2); | ||
expect (state.shouldUpdate ()).to.be.true (); | ||
expect (state.shouldUpdate (0)).to.be.true (); | ||
}); | ||
it ('returns true only for compatible generations', () => { | ||
const store = Store.create (); | ||
store.select ('a'); | ||
const state = store.select ('a.b.c'); | ||
expect (state.generation).to.equal (2); | ||
expect (state.shouldUpdate (1)).to.be.false (); | ||
expect (state.shouldUpdate (2)).to.be.true (); | ||
expect (state.shouldUpdate (3)).to.be.true (); | ||
}); | ||
}); | ||
}); |
@@ -184,2 +184,6 @@ 'use strict'; | ||
} | ||
shouldUpdate (generation) { | ||
return !generation || generation >= this.generation; | ||
} | ||
@@ -186,0 +190,0 @@ static create (...args) { |
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
81652
1884
282