Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

attostore

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

attostore

async json data store

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

attodom

small async json in-memory store with cursors and events, < 3kb min, < 2kb gz

ExampleWhyAPILicense

Examples

import create from 'attostore'

var store = create({
  a: 'myInitValue',
  b:{c: 'myNestedValue'}
})

store.ref().on('b/*', function(val, old, key, obj) {
  console.log('key "c" changed')
})

store.ref(['b', 'c']).on('', function(val, old, key, obj) {
  console.log('key "c" changed')
})

store.ref('b/c').set('newValue').then(function(patch) {
  console.log(patch && patch.length ? 'changed' : 'not changed')
})

store.ref(['b', 'c']).set('anotherValue', function(err, acts) {
  if (!err) console.log(patch && patch.length ? 'changed' : 'not changed')
})

supports different environments

  • CJS: var create = require('attostore')
  • ES modules: import create from 'attostore'
  • browser: var create = window.attostore

Features and Limitations

  • set operations are async to let other external queued operation first
  • available in CommonJS, ES6 modules and browser versions
  • no Promise polyfill included. Not required if callbacks are provided
  • only the last item of an Array can be deleted to avoid shifting of keys

API

attostore(initValue: any): Store

Store

store.ref(path: Array|string|number): Ref store.patch(acts: Array, ondone: (err, acts) => void]): void

Ref

ref.root: Ref ref.parent: Ref

ref.keys(path: Path): Array

ref.set(path: Path, value: any, ondone: (err, acts) => void): void ref.set(path: Path, value: any): Promise ref.del(path: Path, ondone: (err, acts) => void): void ref.del(path: Path): Promise

ref.on(path: Path, handler: (val, old, key)=>void, [, context: any]): Ref ref.once(path: Path, handler: (val, old, key)=>void, [, context: any]): Ref ref.off(path: Path, handler: (val, old, key)=>void, [, context: any]): Ref

ref.query(transform: any => any): Query

Query

query.on(path: Path, handler: (val, old, key)=>void, [, context: any]): Ref query.once(path: Path, handler: (val, old, key)=>void, [, context: any]): Ref query.off(path: Path, handler: (val, old, key)=>void, [, context: any]): Ref

Path

Array|string|number

  • 0, "0", [0], ["0"] are equivalent
  • '', null, undefined are equivalent
  • a/b, ["a", "b"] are equivalent
  • wildcards can be used for listeners: ref.on('*/id', cb)

Acts

Simple patch format for atomic changes:

  • array of keys or string path: [{k: 'a/b/c', v: 'abc'}, {k:['a','b','c']}]
  • set if a value is present, delete is the value is missing

Gotcha

  • No Array splicing to keep the keys unchanged. additions and removals from the end only (eg. push pop)

License

MIT © Hugo Villeneuve

Keywords

FAQs

Package last updated on 30 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc