Kv
a fast, immutable key-value store
Install / Use
/learn @threepointone/KvREADME
kv
- a key-value data structure
- with strings for keys
- 'immutable'
- json/redux friendly
- fast (O(logN)) updates
- fast reads via WeakMap memoization
npm install @threepointone/kv --save
api
import { make, get, set, del, entries, toObject } from '@threepointone/kv'
make(): create a new kv store
let o = make()
-
get(o, key): likeo[key] -
set(o, key, value): like{ ...o, [key]: value } -
del(o, key): like{ ...o, [key]: undefined } -
entries(o): returns an array of[k, v]entries -
toObject(o): returns a regular js object withk:ventries
rationale
(AKA "Why would I use this over Immutable.js/mori/seamless-immutable/etc?")
I made this module for redux-react-local, to solve a very specific use case with unique constraints. Specifically -
- fast writes/updates
- it sticks close to regular json objects, no custom types
- redux friendly, ie - you can stick it on a redux store and it should just work
- server side render friendly - because they're regular objects, one can simply serialize/deserialize across the wire
- did not need Lists, Vectors, etc,
todo
- satisfy Iterable protocol
- compare perf with other libs
- reclaim GC when deleting keys
