Synchronize an observable hash table with an array with primary keys
$ npm install --save observ-sync-hash
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()
//=> {}
Returns an unlisten
function.
Required
Type: function
Required
Type: function
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
.
Type: boolean
Default: false
If true
, data from the array will be added to the hash instead of null
values.
MIT © Ben Drucker