- Manager
Reactive data manager that observes data changes and performs actions in response. Observation is lazy, data is updated only when required.
- ManagerOptions :
Object - Observable
Object or array that will be observed for changes. When the property of type Object or Array of Observable are accessed it automaticaly becomes Observable
- UpdatableFunction
function that caches result of its execution and returns cached value if function state is valid function state can be invalidated if some of Observable objects that were accessed on previous call are changed
- UpdatableSettings :
Object Settings to create UpdatableFunction
Reactive data manager that observes data changes and performs actions in response. Observation is lazy, data is updated only when required.
Kind: global class
- Manager
- new exports.Manager([options])
- .mapProperties(source, target, [propertyKeys])
- .setOptions([options])
- .getOptions() ⇒
ManagerOptions - .makeObservable(dataSource) ⇒
Observable - .makeUpdatable(fn, settings) ⇒
UpdatableFunction - .makeComputed(target, propertyKey, getter, [setter])
- .makeReaction(call, run) ⇒
UpdatableFunction - .getDataSource() ⇒
Object|Array - .isObservable(target)
- .run([action])
- .runDeferred([action], [timeout])
| Param | Type | Description |
|---|---|---|
| [options] | ManagerOptions |
Manager options |
Maps properties from source to target
Kind: instance method of Manager
| Param | Type | Description |
|---|---|---|
| source | Observable |
|
| target | Observable |
|
| [propertyKeys] | Array | String |
property keys of source object to map to target object, if not set then all keys will be mapped |
Dynamically sets the options of the data manager
Kind: instance method of Manager
| Param | Type | Description |
|---|---|---|
| [options] | ManagerOptions |
Manager options |
manager.getOptions() ⇒ ManagerOptions
Gets the options of the data manager
Kind: instance method of Manager
Returns: ManagerOptions - Manager options
manager.makeObservable(dataSource) ⇒ Observable
Creates Observable object for the specified dataSource
Kind: instance method of Manager
Returns: Observable - observable object
| Param | Type | Description |
|---|---|---|
| dataSource | Object | Array |
data source |
manager.makeUpdatable(fn, settings) ⇒ UpdatableFunction
Creates UpdatableFunction Used for internal purposes
Kind: instance method of Manager
| Param | Type | Description |
|---|---|---|
| fn | function |
function that will be called from UpdatableFunction |
| settings | UpdatableSettings |
settings for updatable function |
Creates computed property
Kind: instance method of Manager
| Param | Type | Description |
|---|---|---|
| target | Object |
The object for which the calculated property will be created |
| propertyKey | String |
Name of calculated property |
| getter | function |
The function to be executed when accessing the property |
| [setter] | function |
The function that will be executed when setting the value of the property |
manager.makeReaction(call, run) ⇒ UpdatableFunction
Creates UpdatableFunction that will be automatically executed when one of it's dependencies are changed
Kind: instance method of Manager
| Param | Type | Default | Description |
|---|---|---|---|
| call | function |
Function to call UpdatableFunction 'call' will be executed when some of Observable that was used on previous call are changed | |
| run | Boolean |
true |
Run function immediately after it's registration If ManagerOptions.immediateReaction is not set then it will be called on the next tick. |
Returns original source of Observable
Kind: instance method of Manager
Checks if the object is Observable
Kind: instance method of Manager
| Param | Type |
|---|---|
| target | Observable | Object | Array |
Executes all reactions that marked with invalid state
Kind: instance method of Manager
| Param | Type | Description |
|---|---|---|
| [action] | function |
Changes of Observable that happens inside 'action' function will not trigger immediate execution of dependent reactions If ManagerOptions.immediateReaction is set then reactions will be executed after exiting the 'action' function |
Executes all reactions that marked as invalid Unlike run, 'runDeferred' makes it not immediately but after 'timeout'
Kind: instance method of Manager
| Param | Type | Default | Description |
|---|---|---|---|
| [action] | function |
changes of Observable that happens inside 'action' function will not trigger immediate execution of dependent reactions | |
| [timeout] | Number |
0 |
reactions execution delay |
Kind: global typedef
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [immediateReaction] | Boolean |
false |
if set to true reactions will be executed immediately on same event loop otherwise it will be executed after zero timeout (on next event loop) |
| [enabled] | Boolean |
true |
state of data manager, if it is disabled then reactions will not be executed |
Object or array that will be observed for changes. When the property of type Object or Array of Observable are accessed it automaticaly becomes Observable
function that caches result of its execution and returns cached value if function state is valid function state can be invalidated if some of Observable objects that were accessed on previous call are changed
Kind: global typedef
Properties
| Name | Type |
|---|---|
| uninit | function |
Settings to create UpdatableFunction
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| onInvalidate | function |
callback function that will be executed when UpdatableState of UpdatableFunction becomes invalid |
| onUninit | function |
callback function that will be executed after UpdatableFunction#uninit is called |