-
Notifications
You must be signed in to change notification settings - Fork 8
api
-
- core interface
- common symbol methods
-
default
:- also available named with
Chain
- is a ChainedMap that contains all functionality created by using compose with default arguments
- also available named with
all exports are available as modular imports as well
import ChainedMap from 'chain-able/ChainedMap'
these core functions call chain.store
, when updating the store
, this
is returned, otherwise the value is returned
👍👎 the general rule of thumb is:
- is it a list? use
Set
- otherwise... use
Map
-
clear():
Chain
clears the store, resets to empty -
delete():
Chain
-
has(
key
):bool
-
set(
key
,val
):Chain
-
get(
key
):any
-
clean():
Array
(undefined and null values are removed) -
values():
[index: value]
-
compose([
Classes
,Objects
]):Chain
example -
end():
Chain.parent
-
- when(`condition`, `onTrue`, `onFalse`): `Chain`when(`condition`, `onTrue`, `onFalse`):
Chain
when the condition is true, trueBrancher is called, else, falseBrancher is called
const prod = process.env.NODE_ENV === 'production' chains.when(prod, c => c.set('prod', true), c => c.set('prod', false))
-
from(arg):
Chain
-
a simplified, optimized
.merge
which works similar, but does not deeply merge objects except when there are properties are chainable instances -
defaults to existing any existing values or set them initially, for hydrating or transferring (for example, to-from localstorage, to-from webworker)
-
-
merge(arg):
Chain
const chain = new ChainedMap() chain.merge({ehOh: true}) // same as chain.set('ehOh', true) chain.entries() === {ehOh: true}
- in ChainedSet
arg
is anIteratable
(e.g. Array) - in ChainedMap
arg
is anObject
-
iterate over the object properties: - if there a property matching the key - if it's a chainable instance (e.g. `this.list = new ChainedSet(this)`) - call `.merge` on the instance - if it's a method - if the value is in the store, [tap](tap) the value & deeply merge the value with the existing one - call the method with the value - default to `.set` on the store, merge when existing value
- in ChainedSet
extension of Set
- add(val):
Chain
- prepend(val):
Chain
- merge(
Iteratable
):Chain
- values():
Array
- concat(
Iteratable
):Chain
- append(val):
Chain
extension of Map
-
entries():
{key: value}
-
extend(
Array<string>
):Chain
class Chained extends Chainable {
constructor(parent) {
super(parent)
this.extend(['eh', 'canada'])
}
}
// doing the above is the same as
class Chained extends Chainable {
eh(arg) {
return this.set('eh', arg)
}
canada(arg) {
return this.set('canada', arg)
}
}