0.10.0 • Published 6 years ago

attostore v0.10.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

attostore

small json in-memory store with path events, ~3kb min, ~1kb gz

ExampleWhyAPILicense

Examples

var Store = require('attostore')
var store = new Store({})

store.on('a/b', function(val, key, old) {
  console.log('changed', key, 'from', old, 'to', val)
})

store.run([{path:'a/b', data:'hello'}]) //runs a series of patches
store.set(['a', 'b'], 'world') //directly sets a value

Features, Limitations, Gotcha

  • only the last item of an Array can be deleted to avoid shifting of keys
  • No Array splicing to keep the keys unchanged. additions and removals from the end only (eg. push pop)
  • only JSON types supported (Array, Object, string, number, boolean, null)
  • set triggers a deletion if the value is undefined and/or absent

API

new Store(initValue: any): Store

Store

.on(path: Path, handler: (val, key, old, key)=>void, , context: any): Ref .once(path: Path, handler: (val, key, old, key)=>void, , context: any): Ref .off(path: Path, handler: (val, key, old, key)=>void, , context: any): Ref .run(commandName: string, ...args: any): Error|void .get(path: Path): any .run(command[]): Error|void .set(path: Path , data: any): Error|void

Command

{path: Path, data: any}

Path

Array|string|number

  • 0, "0", [0], ["0"] are equivalent
  • '', null, undefined, [] all point to the root
  • a/b, ["a", "b"] are equivalent

License

MIT © Hugo Villeneuve

0.10.0

6 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.0

7 years ago

0.5.2

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.0.1

7 years ago