Model set and get the data. The changes are propagated using the observe/observable pattern. Changes are propagated in the next thread.
Atom is a model (internally a JSON) where you can set and get data with the following functions:
atom.set('user.email', '[email protected]')
atom.get('user.email') // [email protected]
And you can observe changes in the model with the function:
var myInstance = new MyClass()
atom.on(myInstance, {
paths: 'user.email',
run: 'onUserEmailChange'
})
atom.set('user.email', '[email protected]')
// method myInstance.onUserEmailChange will be executed in the next thread
Atom helps you to apply the observer/observable pattern in a Javascript application.
The propagation of the changes is done in the next Javascript thread, therefore, it minimizes the number of times the data is propagated and saves memory in the call stack.
Uses dot notation to access model elements.
npm run examples
npm run lint
atom.on(context, definitions) // subscribes a method and a model path
atom.off(context) // unsubscribes a method from the model
- context: context where run observable method
- [object|class instance|undefined]
- definitions: an object with properties
- paths: path to observe
- [string|array of strings]
- run: method to run when path's value changes
- [string|function|array of strings and functions]
- if method is a string atom find a method with this name in the context
- run method is executed when a parent or a child of the path changes
- paths: path to observe
at(path, idx, defaultValue)
filter(path, predicate)
find(path, predicate, defaultValue)
get(path)
has(path)
isEmpty(path)
pluck(path, property)
size(path)
concat(path, value = [])
pop(path, defaultValue)
push(path, value)
remove(path, predicate)
reset(path, value = [])
set(path, value)
toggle(path, status)
unset(path)
update(path, value, predicate)
path(...paths) // returns a path in string with dot notation
mixin(mixins) // add mixins to atom
log() // returns a copy of model