Home Reference Source Repository
import ShadowImpl from 'f.lux/src/ShadowImpl.js'
public class | source

ShadowImpl

Indirect Subclass:

IsolatedShadowImpl

The base class for Shadow backing objects. Each shadow property has an 'impl' that performs the f.lux bookkeeping to enable the shadow state to work properly. The 'impl' is broken out from the shadow proper to prevent polluting the namespace with a bunch of crazy looking variables and methods.

A shadow property's 'impl' is available through the Shadow.__ method. Direct access to the 'impl' is rarely needed by custom properties, shadows, or application logic. And there almost certainly no reason to directly subclass this class.

See:

  • Shadow.__

Constructor Summary

Public Constructor
public

constructor(time: *, property: *, name: *, state: *, parent: *, shader: *, prev: *)

Member Summary

Public Members
public
public

[_cache]: {}

public
public
public
public
public
public

[_name]: *

public
public
public
public
public
public
public
public
public
public

[_time]: *

Method Summary

Public Methods
public
public

Maps the getter and setter (if appropriate) onto the parent property.

public

Gets the next model state for the property.

public

Schedules an UPDATE action with the store.

public

[_setupShadow](prev: *, inCtor: *): *

public

access(): *

public

assign(nextState: *, name: *): *

Replace the value of this property.

public

Invoked during defineProperty() to define children properties marked for automount

public

Prevents all children from being able to obtain model in update() callbacks.

public

blockFurtherUpdates(replaced: *)

Prevents this property and descendents from providing a model to update() callbacks.

public

cache(): *

public

changeParent(newParent: *)

public

Subclasses should implement this method in such a way as not to trigger a mapping.

public

Gets the implementation objects managed by this property.

public

copyState(): *

Creates a deep clone of the current property state.

public

createCopy(time: *, newModel: *, parentImpl: *): *

Create a copy of the internals during reshadowing when the property has not changed during the update process but some descendant has been modified.

public

defaults(state: *)

Merges a new state into this property by using the 'state' parameter to set default values, ie it will not overwrite any existing values.

public

Maps all child properties onto this property using Object.defineProperty().

public

definePropertyGetValue(state: *): *

Invoked on shadow getter access to obtain the get value.

public

definePropertySetValue(newValue: *)

Invoked on shadow property assignment to perform the replacement f.lux action.

public

didShadow(time: *, newRoot: *)

public

dispatchUpdate(action: *)

Intended for use by update() and replaying actions.

public

dotPath(): *

Helpful debugging utility that returns the path joined by '.'.

public
public

findByPath(path: *): *

public

getChild(name: *): *

Gets a child implementation matching a property name or undefined if no such property exists.

public

Gets if the property has an child properties (not whether child properties are supported).

public

Gets if an update has occurred directly to this property.

public

invalidate(childImpl: *, source: *)

Marks property and ancestors as invalid.

public

isActive(): *

Gets if the property represents live data.

public

isIsolated(): *

public

isLeaf(): *

public

Gets if defineChildProperties() has been invoked.

public

Gets if this property type reprsents a primitive javascript type.

public

isRoot(): *

public

Gets whether the property value supports calls to update().

public

isValid(): *

Gets if this property or one of its child properties has pending updates.

public

keys()

Gets the keys/indices for this property.

public

latest(): *

public

merge(state: *)

Merges a new state into this property.

public

name(): *

public

nextName(): *

Gets the name after all model updates are performed.

public

nextState(): *

Gets the model as it will be once all pending changes are recorded with the store.

public

obsolete(callback: *)

Marks this property as obsolete.

public
public

obsoleteTree(callback: *)

Marks the entire subtree as inactive, aka dead.

public

Hook for when this property is no longer represented in the system state.

public

onReshadow(prev: *)

Property has just been reshadowed.

public

Hook for when this property is no longer represented in the system state due to a state update - not a replacement.

public

owner(): *

public

parent(): *

public

path(): *

Gets an array with the property names/indices from the root to this property.

public

property(): *

public

readonly(): *

public

replaced(): *

public

reshadowed(prev: *)

Invoked by reshadow() function for invalid parent property implementations when the directly managed state did not change.

public

root(): *

public

setReadonly(readonly: *)

Sets the readonly flag which will prevent a 'set' function being set in defineProeprty().

public

Creates shadow properties for root properties and sets this property on the parent property for non-root properties.

public

shader(state: *): *

Gets the shader needed to recreate the shadow property for the state.

public

shadow(): *

Gets the user facing property represented by this implementation object.

public

slashPath(): *

Helpful debugging utility that returns the path joined by '.'.

public

state(): *

public

store(): *

public

Transfers the nextName to the name attribute.

public

time(): *

public

toJSON(): {"name": *, "path": *, "active": *, "valid": *, "state": *}

Gets a compact version of this internal's state. It does NOT provide a JSON representation of the model state. The actual Property.toJSON() method returns the model JSON representation.

public

toString(): *

public

update(callback: *): boolean

Makes changes to the next property state.

public

updateName(name: *)

Changes the name this property will have after updates.

public

Marks this property as dead.

public

Gets if shadow property is allowing state updates.

public

waitFor(callback: *)

Invokes a callback once all pending changes have occurred.

public

willShadow(parentWillUnshadow: boolean)

Invoked by the shadowing process to invoke appropriate Property life-cycle methods.

Public Constructors

public constructor(time: *, property: *, name: *, state: *, parent: *, shader: *, prev: *) source

Params:

NameTypeAttributeDescription
time *
property *
name *
state *
parent *
shader *
prev *

Public Members

public [_access]: * source

public [_cache]: {} source

public [_changed]: boolean source

public [_dead]: boolean source

public [_didShadowCalled]: boolean source

public [_futureState]: * source

public [_invalid]: boolean source

public [_name]: * source

public [_nextName]: * source

public [_preventUpdates]: boolean source

public [_previousTime]: * source

public [_property]: * source

public [_readonly]: * source

public [_replaced]: boolean source

public [_scheduled]: boolean source

public [_shadow]: * source

public [_state]: * source

public [_time]: * source

Public Methods

public [_createShadow](): * source

Return:

*

public [_defineProperty](prev: *) source

Maps the getter and setter (if appropriate) onto the parent property.

Params:

NameTypeAttributeDescription
prev *

public [_modelForUpdate](): * source

Gets the next model state for the property. This value is used for performing property updates through the update() function.

Calls to update() trigger an update through the dispatcher upon which the new object will be mapped and the store informed of the change.

Return:

*

public [_scheduleUpdate](): * source

Schedules an UPDATE action with the store. On action execution, the new property will be generated and returned to the store.

Return:

*

public [_setupShadow](prev: *, inCtor: *): * source

Params:

NameTypeAttributeDescription
prev *
inCtor *

Return:

*

public access(): * source

Return:

*

public assign(nextState: *, name: *): * source

Replace the value of this property. This will result in this property tree being recreated.

Note: This value will be used directly (not copied) so ensure the state is not altered.

Params:

NameTypeAttributeDescription
nextState *
name *

Return:

*

public automountChildren() source

Invoked during defineProperty() to define children properties marked for automount

public blockFurtherChildUpdates() source

Prevents all children from being able to obtain model in update() callbacks. Update callbacks should invoke this method when they perform wholesale

public blockFurtherUpdates(replaced: *) source

Prevents this property and descendents from providing a model to update() callbacks.

The update() method invokes this method when the callback returns a different object than the one passed into the callback.

Params:

NameTypeAttributeDescription
replaced *

public cache(): * source

Return:

*

public changeParent(newParent: *) source

Params:

NameTypeAttributeDescription
newParent *

public childCount(): number source

Subclasses should implement this method in such a way as not to trigger a mapping.

Return:

number

public children() source

Gets the implementation objects managed by this property.

public copyState(): * source

Creates a deep clone of the current property state.

Return:

*

public createCopy(time: *, newModel: *, parentImpl: *): * source

Create a copy of the internals during reshadowing when the property has not changed during the update process but some descendant has been modified.

Params:

NameTypeAttributeDescription
time *
newModel *
parentImpl *

Return:

*

public defaults(state: *) source

Merges a new state into this property by using the 'state' parameter to set default values, ie it will not overwrite any existing values. Useful when model objects arrive from external sources, such as an asyncrhonous save or a websocket based update.

Params:

NameTypeAttributeDescription
state *

public defineChildProperties(prev: ShadowImpl, inCtor: boolean) source

Maps all child properties onto this property using Object.defineProperty().

Params:

NameTypeAttributeDescription
prev ShadowImpl

the previous property shadow implementation instance.

inCtor boolean

true if call occuring during shadowing process.

public definePropertyGetValue(state: *): * source

Invoked on shadow getter access to obtain the get value.

The default implementation returns the shadow.

Params:

NameTypeAttributeDescription
state *

Return:

*

the shadow or other f.lux representative value for the shadow proeprty.

public definePropertySetValue(newValue: *) source

Invoked on shadow property assignment to perform the replacement f.lux action.

The default implementation is to assign the new value with no checking.

Params:

NameTypeAttributeDescription
newValue *

the new state value

public didShadow(time: *, newRoot: *) source

Params:

NameTypeAttributeDescription
time *
newRoot *

public dispatchUpdate(action: *) source

Intended for use by update() and replaying actions.

Params:

NameTypeAttributeDescription
action *

public dotPath(): * source

Helpful debugging utility that returns the path joined by '.'. The root node will return the word 'root' for the path.

Return:

*

public ensureMounted() source

public findByPath(path: *): * source

Params:

NameTypeAttributeDescription
path *

Return:

*

public getChild(name: *): * source

Gets a child implementation matching a property name or undefined if no such property exists.

Params:

NameTypeAttributeDescription
name *

Return:

*

public hasChildren(): * source

Gets if the property has an child properties (not whether child properties are supported).

Return:

*

public hasPendingChanges(): * source

Gets if an update has occurred directly to this property.

Return:

*

public invalidate(childImpl: *, source: *) source

Marks property and ancestors as invalid. This means this property or one of its children has been updated. The invalid flag is set to the earliest timestamp when this property or one of its children was changed.

Parameters: childImpl - the child implementation triggering this call or undefined if this implementation started the invalidation process source - the shadow implementation that triggered the invalidation

Params:

NameTypeAttributeDescription
childImpl *
source *
  • optional

public isActive(): * source

Gets if the property represents live data.

Return:

*

public isIsolated(): * source

Return:

*

public isLeaf(): * source

Return:

*

public isMapped(): boolean source

Gets if defineChildProperties() has been invoked.

Return:

boolean

public isPrimitive(): boolean source

Gets if this property type reprsents a primitive javascript type.

Return:

boolean

public isRoot(): * source

Return:

*

public isUpdatable(): boolean source

Gets whether the property value supports calls to update().

Return:

boolean

public isValid(): * source

Gets if this property or one of its child properties has pending updates. Returns true if there are no pending updates.

Return:

*

public keys() source

Gets the keys/indices for this property.

Implementation note: Subclasses should implement this method in such a way as not to trigger a mapping.

public latest(): * source

Return:

*

public merge(state: *) source

Merges a new state into this property. Useful when model objects arrive from external sources, such as an asyncrhonous save or a websocket based update.

Params:

NameTypeAttributeDescription
state *

public name(): * source

Return:

*

public nextName(): * source

Gets the name after all model updates are performed.

Return:

*

public nextState(): * source

Gets the model as it will be once all pending changes are recorded with the store. This must not be altered.

Return:

*

public obsolete(callback: *) source

Marks this property as obsolete. Once marked obsolete a property may not interact with the store. A property becomes obsolete after it's value or ancestor's value has changed and the update process has completed.

This method does not affect subproperties.

Params:

NameTypeAttributeDescription
callback *

public obsoleteChildren() source

public obsoleteTree(callback: *) source

Marks the entire subtree as inactive, aka dead.

Params:

NameTypeAttributeDescription
callback *

public onReplaced() source

Hook for when this property is no longer represented in the system state.

public onReshadow(prev: *) source

Property has just been reshadowed.

Params:

NameTypeAttributeDescription
prev *

public onUpdate() source

Hook for when this property is no longer represented in the system state due to a state update - not a replacement.

public owner(): * source

Return:

*

public parent(): * source

Return:

*

public path(): * source

Gets an array with the property names/indices from the root to this property.

Return:

*

public property(): * source

Return:

*

public readonly(): * source

Return:

*

public replaced(): * source

Return:

*

public reshadowed(prev: *) source

Invoked by reshadow() function for invalid parent property implementations when the directly managed state did not change.

Calls the onReshadow(prev) method to provide subclasses an oppotunity to setup for futher action after a parent change.

Params:

NameTypeAttributeDescription
prev *

public root(): * source

Return:

*

public setReadonly(readonly: *) source

Sets the readonly flag which will prevent a 'set' function being set in defineProeprty().

Note: this method must be called before defineProperty() is invoked or it will have no affect.

Params:

NameTypeAttributeDescription
readonly *

public setupPropertyAccess(prev: *) source

Creates shadow properties for root properties and sets this property on the parent property for non-root properties.

Note: This method is called by shadowProperty() and reshadow() functions.

Params:

NameTypeAttributeDescription
prev *

public shader(state: *): * source

Gets the shader needed to recreate the shadow property for the state.

Params:

NameTypeAttributeDescription
state *

Return:

*

public shadow(): * source

Gets the user facing property represented by this implementation object.

Return:

*

public slashPath(): * source

Helpful debugging utility that returns the path joined by '.'. The root node will return the word 'root' for the path.

Return:

*

public state(): * source

Return:

*

public store(): * source

Return:

*

public switchName() source

Transfers the nextName to the name attribute.

public time(): * source

Return:

*

public toJSON(): {"name": *, "path": *, "active": *, "valid": *, "state": *} source

Gets a compact version of this internal's state. It does NOT provide a JSON representation of the model state. The actual Property.toJSON() method returns the model JSON representation.

Return:

{"name": *, "path": *, "active": *, "valid": *, "state": *}

public toString(): * source

Return:

*

public update(callback: *): boolean source

Makes changes to the next property state. The callback should be pure (no side affects) but that is not a requirement. The callback must be of the form:

(state) => return { nextState, replace }

where: state - the next property state nextState - the state following the callback replace - boolean for whether nextState replaces the current value. The implication of true is that this property and all of it's children will not be able to make future changes to the model.

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

Thus, oldB.c may change oldB'c property 'c' to 5 but model.a.b is still "foo".

Params:

NameTypeAttributeDescription
callback *

Return:

boolean

public updateName(name: *) source

Changes the name this property will have after updates. This is used when moving properties around in the model, such as when splice is used on an array. The nextName() method will return the property name for after updates are applied.

Note: this method does not have any side effects beyond setting the _nextName instance variable. Subclasss will need to perform any book keeping associated with sub-properties.

Params:

NameTypeAttributeDescription
name *

public updated() source

Marks this property as dead. Once marked obsolete a property may not accept further updates. A property is updated when the state changes but not a wholesale replacement or a descendents's value has changed and the update process has completed.

This method does not affect subproperties.

public updatesAllowed(): boolean source

Gets if shadow property is allowing state updates.

Return:

boolean

false if the property or its parent has been replaced, true otherwise.

public waitFor(callback: *) source

Invokes a callback once all pending changes have occurred. The callback should have the form:

callback(property, implementation)

where the property and implementation arguments are the latest version if they still exist.

This method is safe to call on a dead property.

Params:

NameTypeAttributeDescription
callback *

public willShadow(parentWillUnshadow: boolean) source

Invoked by the shadowing process to invoke appropriate Property life-cycle methods. The method name is a reflection that shadow state tree invocation chain for willShadow() occurs when the Store is going to shadow that state.

Params:

NameTypeAttributeDescription
parentWillUnshadow boolean

true when parent property is unshadowing.