electrum-store
Advanced tools
Comparing version 3.6.0 to 3.6.1
@@ -150,3 +150,11 @@ 'use strict'; | ||
const length = prefix.length; | ||
const arities = ids.filter(id => id.startsWith(prefix) && id.indexOf('.', length) < 0); | ||
let arities = ids.filter(id => id.startsWith(prefix) && id.indexOf('.', length) < 0); | ||
const strip = _state2.default.getParentId(startId).length + 1; | ||
if (strip > 1) { | ||
arities = arities.map(id => id.substr(strip)); | ||
} | ||
arities.sort(arityComparer); | ||
@@ -153,0 +161,0 @@ return arities; |
{ | ||
"name": "electrum-store", | ||
"version": "3.6.0", | ||
"version": "3.6.1", | ||
"description": "Electrum store provides a store implementation tailored for Electrum.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -321,2 +321,12 @@ # Electrum Store | ||
## Arity | ||
If you are using the special _arity_ notation defined by Lydia (`a$0`, `a$1`, | ||
etc.), then you might be interested in: | ||
* `arities` → an array of all the sibling `key`s found for the current | ||
node. | ||
Example: say we have nodes `a.b.c`, `a.b.c$0` and `a.b.c$1`, then calling | ||
`store.find ('a.b.c').arities` will return `['c$0', 'c$1']`. | ||
## Working with state ids | ||
@@ -323,0 +333,0 @@ |
@@ -330,2 +330,14 @@ /* global describe it */ | ||
it ('returns sorted arity keys in deep node', () => { | ||
const store = Store.create (); | ||
store.select ('x.a$1'); | ||
store.select ('x.a$10'); | ||
store.select ('x.a$3'); | ||
store.select ('x.a$2.x'); | ||
store.select ('x.a.b.c'); | ||
const state = store.find ('x.a'); | ||
const arr = state.arities; | ||
expect (arr).to.deep.equal (['a$1', 'a$2', 'a$3', 'a$10']); | ||
}); | ||
it ('returns an empty array for an empty state', () => { | ||
@@ -332,0 +344,0 @@ const store = Store.create (); |
@@ -131,3 +131,11 @@ 'use strict'; | ||
const length = prefix.length; | ||
const arities = ids.filter (id => id.startsWith (prefix) && id.indexOf ('.', length) < 0); | ||
let arities = ids.filter (id => id.startsWith (prefix) && id.indexOf ('.', length) < 0); | ||
const strip = State.getParentId (startId).length + 1; | ||
if (strip > 1) { | ||
arities = arities.map (id => id.substr (strip)); | ||
} | ||
arities.sort (arityComparer); | ||
@@ -134,0 +142,0 @@ return arities; |
121912
2701
475