cerebral-addons
Additional utilities for use with cerebral/operators
Usage
;;
Getters/Setters
cerebral-operators supports custom getter and setter functions in place of strings. If either of these functions is detected to by async (indicated by the returning of a promise) then the addon must be marked as async in the chain and subsequently define success and error paths.
getters
A getter is a function that accepts the args passed to an action method and returns some value.
// getter should return a value or a promise which will later resolve to a valuepromise
Example
an example getter might get some data from the server:
// define the getter { return { return { } }} // use the getter success: error:
setters
A setter is a function that accepts the args passed to an action method and the value to set.
// if the setter returns a promise then the addon will wait for it to resolve before continuingpromise
if the setter is async then the addon will also pass on the resolve value to the success chain
Example
an example setter might post some data to the server:
// define the setter { return { return { } }} // use the setter success: error:
included getters
cerebral-addons includes the following getters
and
true: false:
compose
Compose replaces all getters found in object given to the compose factory with the runtime values
Compose doesn't currently support async getters
get
see compose
isEqual
true: false:
isDeepEqual
true: false:
literal
not
true: false:
or
true: false:
findWhere
pop
pop also modifies the array in the state
shift
shift also modifies the array in the state
Included setters
cerebral-addons includes the following setters
merge
push
unshift
Note on Adblockers
Some adblockers such as uBlock Origin may block access to pop.js
during development. This can
be resolved by turning off ad blocking for localhost or using webpack (or similar) for
development. This shouldn't be an issue for production deployments if you are packaging your
production dependencies in a combined .min.js
.
Contribute
Fork repo
npm install
npm start
runs dev mode which watches for changes and auto lints, tests and buildsnpm test
runs the testsnpm run lint
lints the codenpm run build
compiles es2015 to es5