daypack
v2.6.2
Published
A JavaScript library for flattening and reassembling object graphs.
Downloads
7
Readme
daypack
A JavaScript library for flattening and reassembling object graphs.
purpose
This library was written to handle packing up deep JS object graphs to send over the wire. It does this by traversing the entire graph recursively, and packing entities into a flat data structure.
This library is similar to normalizr, but with a few differences:
- All ids need to be unique.
- You don't need to define a schema, or know the type of an entity to pack/unpack it.
- You can use this library to serialize/deserialize JS class instances, as long as you register a custom packer/unpacker for it.
api
Daypack : object
Kind: global namespace
- Daypack : object
daypack.withHeap ⇒
withHeap
allows you to manually set the heap for a pack
Kind: instance property of Daypack
Returns: this
Params
- heap
daypack.withHead ⇒
withHead
allows you to manually set the head for a pack
Kind: instance property of Daypack
Returns: this
Params
- head
daypack.pack ⇒
pack
packs a value into the heap, and updates the head
Kind: instance property of Daypack
Returns: this
Params
- val
daypack.packHeap ⇒
packHeap
packs a value into the heap, but does not update the head
Kind: instance property of Daypack
Returns: this
Params
- val
daypack.unpack ⇒
unpack
unpacks the head, or accepts an optional "head" to unpack
Kind: instance property of Daypack
Returns: the unpacked head
Params
- val - an optional "head" to use as a base point for unpacking
daypack.each ⇒
each
unpacks everything in the heap in isolation, and calls the 'each' function on it
Kind: instance property of Daypack
Returns: this
Params
- func - an each function to call
daypack.filter ⇒
filter
unpacks everything in the heap in isolation, and calls the 'filter' function on it,
to build a new pack
Kind: instance property of Daypack
Returns: a new DayPack instance with only the filtered entities in the heap
Params
- func - a filter function to call
daypack.map ⇒
map
unpacks everything in the heap in isolation, and calls the 'map' function on it,
to build a new pack
Kind: instance property of Daypack
Returns: a new DayPack instance with the mapped entities in the heap
Params
- func - a map function to call
daypack.reduce ⇒
reduce
unpacks everything in the heap in isolation, and calls the 'reducer' function on it,
to build a new reduced result
Kind: instance property of Daypack
Returns: a new DayPack instance with only the filtered entities in the heap
Params
- func - a filter function to call
daypack.toObject ⇒
toObject
converts the pack into a serializable object
Kind: instance property of Daypack
Returns: a serializable version of the pack
daypack.fromObject ⇒
fromObject
de-serializes a serialized version into a DayPack instance
Kind: instance property of Daypack
Returns: this
Params
- obj - the object to unpack
daypack.toJSON ⇒
toJSON
converts the pack into a JSON object
Kind: instance property of Daypack
Returns: a JSON string
daypack.fromJSON ⇒
fromJSON
de-serialized a JSON string into this pack
Kind: instance property of Daypack
Returns: a JSON string
Params
- json - the json to unpack
daypack.fromJSON ⇒
fromJSON
de-serialized a JSON string into this pack
Kind: instance property of Daypack
Returns: a JSON string
Params
- json - the json to unpack
Daypack.Daypack
Kind: static class of Daypack
Daypack.clone(val) ⇒
A function that packs a JavaScript value.
Kind: static method of Daypack
Returns: an flattened object
Params
- val - the value to pack