observ-sync-hash

2.1.1 • Public • Published

observ-sync-hash Build Status

Synchronize an observable hash table with an array with primary keys

Install

$ npm install --save observ-sync-hash

Usage

var sync = require('observ-sync-hash')
var ObservArray = require('observ-array')
var Hash = require('observ-varhash')

var array = ObservArray([])
var hash = Hash({})

sync(array, hash)

array.push(123)
hash()
//=> {123: null}

array.splice(0, 1)
hash()
//=> {}

API

sync(array, hash, [key]) -> function

Returns an unlisten function.

array

Required
Type: function

An observable array

hash

Required
Type: function

An observable hash

options
key

Type: string

If provided, the hash keys will be derived from a property of each array item instead of the string values themselves. You can use id or even dot syntax, e.g. foo.id.

values

Type: boolean
Default: false

If true, data from the array will be added to the hash instead of null values.

License

MIT © Ben Drucker

Package Sidebar

Install

npm i observ-sync-hash

Weekly Downloads

1

Version

2.1.1

License

MIT

Last publish

Collaborators

  • bendrucker