⁘ common.helpers

OptionsHandler

A OptionHandler is an helper class to bind value update to callbacks & functions. It is designed for objects that commonly accept an arbitrary set of options with or without default values.

go to → Members

Constructor

new OptionsHandler(p_wrapUpFnopt, p_beginFnopt, p_defaultsopt)

TODO

Parameters:
Name Type Attributes Default Description
p_wrapUpFn function <optional>
null
p_beginFn function <optional>
null
p_defaults function <optional>
null

Members

beginFn :function

A unique function to be called before the option handler starts its update cycle.
That callback will be provided with the input options allowing for some preparations or alterations.

defaults :object

Default options values

wrapUpFn

A unique function to be called when the option handler is done processing its update cycle.
The callback will be provided with the input options allowing for some wrap-up operations to take place.

Methods

Clear()

Resets the handler, removing all registered hooks.

Hook(p_optionID, p_fnopt, p_defaultopt)

Hook an option ID to a function or member ID.

Parameters:
Name Type Attributes Default Description
p_optionID string
p_fn function | string <optional>
null

If left null, the hook is assumed to be a setter with the same name as the optionID.

p_default * <optional>

Process(p_target, p_options, p_altOptions)

Process an option object and trigger associated callbacks with the option value as well as the options themselves.

Parameters:
Name Type Default Description
p_target *

target object on which properties are set, and functions are called.

p_options object
p_altOptions object null

an alternative set of options to forward to handlers (used when appending options)

ProcessSingle(p_target, p_optionID, p_optionValue, p_others, p_wrapUp)

Process a single option.
Will not call beginFn.

Parameters:
Name Type Default Description
p_target *
p_optionID string
p_optionValue *
p_others * null

An alternative set of options.

p_wrapUp boolean false

whether or not to wrap-up option call

UnHook(p_optionID, p_fnopt)

Removes handlers associated with a given option ID

Parameters:
Name Type Attributes Default Description
p_optionID string
p_fn function | string <optional>
null