Skip to content

Latest commit

 

History

History
227 lines (163 loc) · 9.27 KB

File metadata and controls

227 lines (163 loc) · 9.27 KB

Classes

Manager

Reactive data manager that observes data changes and performs actions in response. Observation is lazy, data is updated only when required.

Typedefs

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

Manager

Reactive data manager that observes data changes and performs actions in response. Observation is lazy, data is updated only when required.

Kind: global class

new exports.Manager([options])

Param Type Description
[options] ManagerOptions Manager options

manager.mapProperties(source, target, [propertyKeys])

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

manager.setOptions([options])

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

manager.makeComputed(target, propertyKey, getter, [setter])

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.

manager.getDataSource() ⇒ Object | Array

Returns original source of Observable

Kind: instance method of Manager

manager.isObservable(target)

Checks if the object is Observable

Kind: instance method of Manager

Param Type
target Observable | Object | Array

manager.run([action])

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

manager.runDeferred([action], [timeout])

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

ManagerOptions : Object

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

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

Kind: global typedef

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

Kind: global typedef
Properties

Name Type
uninit function

UpdatableSettings : Object

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