0.1.0 • Published 4 years ago
indexed-values v0.1.0
indexed-values
Example
import {IndexedValues} from 'indexed-values';
// create a Set of unique values
const main = new IndexedValues;
// derive a set
const sub1 = main.bindValues(["a", "b", "c"]);
const sub2 = main.bindValues(["a"]);
// derived sets can make the main Set grow
if (!sub2.has("d"))
sub2.add("d");
// {"main":["a","b","c","d"],"data":[[0,1,2],[0,3]]}
console.log(JSON.stringify({
main,
data: [sub1, sub2]
}));API
The IndexedValues constructor extends the Set class, but it's a facade with the following peculiarities:
- it is not posible to
deletea single value, orclearthe instance.IndexedValuesinstances are ever-growing .toJSON()method returns an array of values held internally.valueOf()method returns a realSetthat can resistpostMessage, or be stored asIndexedDB.bindValues(values = [])returns aSetthat can contain, add, or remove, any value. Added values will be reflected in theIndexedValuesinstance that created the boundSet..bindIndexes(indexes = [])is like.bindValues()but uses indexes instead, to initialize the derivedSet. This is mostly useful for revival..mapKeys(entries = [])returns aMapwhere keys are derived from theIndexedValues. Added keys that are not known in theIndexedValuessource, will be automatically added as part of theSet. Once serialized as JSON, these maps will represent all keys as indexes, because indeed these maps never hold keys as values, these hold keys as indexes..mapEntries(entries = [])is the revival counter-part of.mapKeys(). It returns a map with keys revived from theIndexedValuesinstance..fromIndexes(indexes)can revive right awaySetinstances, upgrading their prototype. This is a quick and dirty.bindIndexes()equivalent, available for performance reasons..fromEntries(entries)can revive right awayMapinstances, upgrading their prototype. This is a quick and dirty.mapEntries()equivalent, available for performance reasons.