Property
Direct Subclass:
Indirect Subclass:
Base class for custom f.lux properties. A Property
has a lifespan from when the state property
is mapped until it is replaced/deleted. This differs from Shadow as its lifespan
that lasts from the time of mapping until the state property is replaced/deleted OR the
shadow property is invalidated due to a local change or a descendant property change.
Most shadow state properties can be implemented without writing a Property
subclass, relying on
autoshadowing, or defining the state structure using StateType along with one of the
built-in property class createClass()
static methods. The primary reason for writing a
Property
subclass is to tie into the f.lux property life-cycle.
This class provides an experimental check pointing api. Check pointing allows the state to be recorded at a point in time and then later reset to that point. This is handy when a form may accept changes and then allow the user to cancel the edit session.
Life cycle methods:
propertyWillShadow()
- invoked just before a state property is going to be shadowed using this instance. Shadow state is not valid during this method.propertyDidShadow()
- property was shadowed and fully functional.propertyChildInvalidated(childProperty, sourceProperty)
- a child property mutation action has occurred and it's value will change in store's next update.propertyDidUpdate()
- state managed by this property has changed.propertyWillUnshadow()
- invoked just before the shadow property is removed from the shadow state because the state property being shadowed has been removed from the application state.
Constructor Summary
Public Constructor | ||
public |
constructor(stateType: StateType) If a StateType is not passed to this constructor then one is located using StateType.from thus ensuring the f.lux shadowing process is defined for this property. |
Member Summary
Public Members | ||
public |
|
|
public |
|
|
public |
|
|
public |
[_checkpoint]: {"data": *} |
|
public |
[_impl]: * |
|
public |
|
|
public |
[_mixins]: *[] |
|
public |
[_parent]: * |
|
public |
[_pid]: * |
|
public |
[_readonly]: * |
|
public |
[_shader]: * |
|
public |
[_stateType]: * |
|
public |
[_store]: * |
Method Summary
Public Methods | ||
public |
Use this.$$() in shadow methods to get access to the property. |
|
public |
Gets if autoshadowing is enabled for this property. |
|
public |
Copies the current actual state for later reset using Property#resetToCheckpoint. |
|
public |
Clears an existing checkpoint created using Property#checkpoint. |
|
public |
Creates the object to be assigned to the shadow.$ property. |
|
public |
Gets the path from root property using a dot ( |
|
public |
getCheckpoint(): * Gets the checkpoint state previously recorded using Property#checkpoint. |
|
public |
getInitialState(state: *): * Gets the initial state for a property at the beginning of the property mounting process. |
|
public |
Gets if an existing checkpoint has be created using Property#checkpoint. |
|
public |
initialState(): * Gets the result from StateType#computeInitialState. |
|
public |
Gets if the property is currently shadowing an actual state property. |
|
public |
Gets if property is an actual isolated property managed by the store. |
|
public |
Gets if the property allows for assignment through the shadow state, ie |
|
public |
Gets if this is the shadow state root property. |
|
public |
The property name by which this property is referenced by the Property.parent. |
|
public |
nextState(): * Gets what the actual state for this property will be after the Store updates all pending actions. |
|
public |
Gets the object containing or managing this property. |
|
public |
Gets the parent property. |
|
public |
Gets the parent's shadow property. |
|
public |
path(): [] Gets the Property#name components from the root property to this property. |
|
public |
Gets the unique f.lux ID for this property. |
|
public |
propertyChildInvalidated(childProperty: Property, sourceProperty: Property) A child property or one of its descendents wil be changing state. |
|
public |
Invoked by the f.lux shadowing process after a property initially shadows a state property. |
|
public |
Invoked by the f.lux shadowing process after a property is reshadowed. |
|
public |
Invoked by the f.lux shadowing process just before a property initially shadows a state property. |
|
public |
Invoked by the f.lux shadowing process just before a property will be removed from the shadow state. |
|
public |
Replaces the current property state with a checkpoint state previously recorded using Property#checkpoint. |
|
public |
Gets the shadow state root property for the Store managing this property. |
|
public |
rootShadow(): Shadow Gets the root shadow state for the Store managing this property. |
|
public |
setAutoshadow(auto: boolean): * Sets the auto shadow property flag. |
|
public |
setImplementationClass(ImplClass: *) |
|
public |
setInitialState(state: *): Property Explicitly sets an initial state that will be used if the state tree does not have a value for this property. |
|
public |
setReadonly(readonly: *) Sets the readonly flag which will prevent an assignment from changing the value. |
|
public |
setShadowClass(ShadowClass: Shadow) Sets the class to be used for the shadow api |
|
public |
shader(state: *): * Gets the Shader instance for this property. |
|
public |
shadowClass(): * Returns the Shadow subclass used to virtualize the state property. |
|
public |
Gets the path from root property using a slash ( |
|
public |
state(): * Gets the actual state being shadowed. |
|
public |
stateType(): * Gets the StateType used for creating this property. |
|
public |
store(): * Gets the {@Link Store} containing the application state. |
|
public |
touch() Triggers a reshadow of the properties shadow state. |
|
public |
typeName(): * Gets this property's StateType.typeName value. |
|
public |
Makes changes to the next proeprty state. |
Public Constructors
public constructor(stateType: StateType) source
If a StateType is not passed to this constructor then one is located using StateType.from thus ensuring the f.lux shadowing process is defined for this property.
Public Members
public [_ImplementationClass]: * source
public [_ShadowClass]: * source
public [_autoShadow]: * source
public [_checkpoint]: {"data": *} source
public [_impl]: * source
public [_initialState]: * source
public [_mixins]: *[] source
public [_parent]: * source
public [_pid]: * source
public [_readonly]: * source
public [_shader]: * source
public [_stateType]: * source
public [_store]: * source
Public Methods
public $$(): Property source
Use this.$$() in shadow methods to get access to the property. Useful in Property
subclass
@shadow
methods since the method will be bound to the shadow. Exposing on the Property
allows for the same code to work when called as a member function using this
or
called through a shadow function.
public autoShadow(): boolean source
Gets if autoshadowing is enabled for this property. Unlike the Property#readonly shadowing attribute, autoshadowing is not hierarchically determined.
public checkpoint() source
Copies the current actual state for later reset using Property#resetToCheckpoint. An existing checkpoint will take precedence over subsequent calls.
public create$(impl: *): Access source
Creates the object to be assigned to the shadow.$ property. Subclasses can override this method
to setup a chain of specialized accessors ($()
). See Access for details on setting up
specialized accessors. This is an advanced feature and rarely required.
Params:
Name | Type | Attribute | Description |
impl | * |
public dotPath(): string source
Gets the path from root property using a dot (.
) separator. Suitable for using with the lodash result()
function.
public getCheckpoint(): * source
Gets the checkpoint state previously recorded using Property#checkpoint.
Return:
* | the checkpoint data if checkpoint is set. |
public getInitialState(state: *): * source
Gets the initial state for a property at the beginning of the property mounting process. This
implementation merges the StateType#initialStateWithDefaults, the initial state set using
#setInitialState, and the state passed in from the existing store state. The store's state property
values take precedence. The explicitly set initial state is used only when the state
parameter is
undefined
.
Params:
Name | Type | Attribute | Description |
state | * | the store's property state at the time of mounting. |
Return:
* | merged state with the state parameter taking precedence if the initial state is set otherwise returns the state parameter. This base implementation simply returns the state parameter |
public hasCheckpoint(): boolean source
Gets if an existing checkpoint has be created using Property#checkpoint.
public isActive(): boolean source
Gets if the property is currently shadowing an actual state property.
public isIsolated(): boolean source
Gets if property is an actual isolated property managed by the store. This implementation always returns false. Override to change behavior.
public isReadonly(): boolean source
Gets if the property allows for assignment through the shadow state, ie todo.desc = "go skiing"
. The
readonly attribute is hierarchically determined through the parent property if not explicitly set.
public name(): string | number source
The property name by which this property is referenced by the Property.parent.
public nextState(): * source
Gets what the actual state for this property will be after the Store updates all pending actions.
Return:
* | the next state or |
public owner(): Property source
Gets the object containing or managing this property. All properties have an owner except the root property. Isolated properties are a case where a property is independently managed by the store so it can have an owner but not a parent.
public path(): [] source
Gets the Property#name components from the root property to this property.
Return:
[] | array where each name component is either a |
public propertyChildInvalidated(childProperty: Property, sourceProperty: Property) source
A child property or one of its descendents wil be changing state. Useful hook when a property needs to perform some bookkeepng for child properties. Utilizing this hook provides a chance to make tracking changes in shadow properties before the store updates its state.
Subclasses do not need to invoke the parent implementation.
public propertyDidShadow() source
Invoked by the f.lux shadowing process after a property initially shadows a state property. The property is active and can safely access the shadow state.
Subclasses do not need to invoke the parent implementation.
public propertyDidUpdate() source
Invoked by the f.lux shadowing process after a property is reshadowed.
Subclasses do not need to invoke the parent implementation.
public propertyWillShadow() source
Invoked by the f.lux shadowing process just before a property initially shadows a state property. The property is not active when this method is invoked so state values cannot be accessed. This method is useful for constructor type activities when you do not want to implement a constructor.
Subclasses do not need to invoke the parent implementation.
public propertyWillUnshadow() source
Invoked by the f.lux shadowing process just before a property will be removed from the shadow state.
Subclasses do not need to invoke the parent implementation.
public resetToCheckpoint() source
Replaces the current property state with a checkpoint state previously recorded using Property#checkpoint. The checkpoint is cleared.
public root(): Property source
Gets the shadow state root property for the Store managing this property.
public setAutoshadow(auto: boolean): * source
Sets the auto shadow property flag.
Note: this method is rarely required as the StateType will usually configure this attribute.
Params:
Name | Type | Attribute | Description |
auto | boolean | boolean where true means to auto map subproperties. |
Return:
* | reference to this property object. |
public setImplementationClass(ImplClass: *) source
Params:
Name | Type | Attribute | Description |
ImplClass | * |
public setInitialState(state: *): Property source
Explicitly sets an initial state that will be used if the state tree does not have a value for this property. This value is used by Property#getInitialState and is merged using StateType#initialStateWithDefaults.
Note: this method is rarely required as the StateType will usually configure this attribute.
Params:
Name | Type | Attribute | Description |
state | * | the initial state for the property |
public setReadonly(readonly: *) source
Sets the readonly flag which will prevent an assignment from changing the value. More technically, a 'set' function being set in the implementation's defineProeprty().
Note: this method is rarely required as the StateType will usually configure this attribute.
Params:
Name | Type | Attribute | Description |
readonly | * |
public shader(state: *): * source
Gets the Shader instance for this property.
Params:
Name | Type | Attribute | Description |
state | * |
Return:
* |
public shadowClass(): * source
Returns the Shadow subclass used to virtualize the state property.
Returns - Shadow class
Return:
* |
public touch() source
Triggers a reshadow of the properties shadow state. This is handy when a calculated state value changes while concrete state values remain unchanged.
public update(callback: function) source
Makes changes to the next proeprty state. The callback should be pure (no side affects).
The callback has the form:
function callback(state) : { name, nextState, replace }
where:
state
- the current statenextState
- the next state for the propertyname
- the name of the action, such as "assign()" (optional)replace
- should the entire state for this property be replaced withnextState
. A value oftrue
means this property will unshadow and all of it's children will not be able to make future changes to the model. (optional - default=false)
The callback return value is called an action descriptor and describes the update behavior.To understand the reasoning behind the replace flag consider the following example:
``` const model = { a: { b: { c: 1 } } } const oldB = model.a.b
model.a.b = "foo" oldB.c = 5
model.a.b.c === undefined ```js
Thus, oldB.c may change oldB'c property 'c' to 5 but model.a.b is still "foo".
Params:
Name | Type | Attribute | Description |
callback | function | takes the current state and returns an object containing
the action descriptor (see discussion above). At a minimum, the action descriptor must contain
a |