    import ShadowImpl from 'f.lux/src/ShadowImpl.js'

public class | source

# ShadowImpl

#### Direct Subclass:

IndexedShadowImpl, IsolatedObjectShadowImpl, ObjectShadowImpl, PrimitiveShadowImpl

#### 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 | [_access]: * |
public | [_cache]: {} |
public | [_changed]: boolean |
public | [_dead]: boolean |
public | [_didShadowCalled]: boolean |
public | [_futureState]: * |
public | [_invalid]: boolean |
public | [_name]: * |
public | [_nextName]: * |
public | [_preventUpdates]: boolean |
public | [_previousTime]: * |
public | [_property]: * |
public | [_readonly]: * |
public | [_replaced]: boolean |
public | [_scheduled]: boolean |
public | [_shadow]: * |
public | [_state]: * |
public | [_time]: * |

## Method Summary

Public Methods
public | [_createShadow](): * |
public | [_defineProperty](prev: *) Maps the getter and setter (if appropriate) onto the parent property. |
public | [_modelForUpdate](): * Gets the next model state for the property. |
public | [_scheduleUpdate](): * Schedules an UPDATE action with the store. |
public | [_setupShadow](prev: *, inCtor: *): * |
public | access(): * |
public | assign(nextState: *, name: *): * Replace the value of this property. |
public | automountChildren() Invoked during defineProperty() to define children properties marked for automount |
public | blockFurtherChildUpdates() 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 | childCount(): number Subclasses should implement this method in such a way as not to trigger a mapping. |
public | children() 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 | defineChildProperties(prev: ShadowImpl, inCtor: boolean) 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 | ensureMounted() |
public | findByPath(path: *): * |
public | getChild(name: *): * Gets a child implementation matching a property name or undefined if no such property exists. |
public | hasChildren(): * Gets if the property has an child properties (not whether child properties are supported). |
public | hasPendingChanges(): * 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 | isMapped(): boolean Gets if defineChildProperties() has been invoked. |
public | isPrimitive(): boolean Gets if this property type reprsents a primitive javascript type. |
public | isRoot(): * |
public | isUpdatable(): boolean 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 | obsoleteChildren() |
public | obsoleteTree(callback: *) Marks the entire subtree as inactive, aka dead. |
public | onReplaced() Hook for when this property is no longer represented in the system state. |
public | onReshadow(prev: *) Property has just been reshadowed. |
public | onUpdate() 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 | setupPropertyAccess(prev: *) 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 | switchName() 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 | updated() Marks this property as dead. |
public | updatesAllowed(): boolean 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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
replaced | * |  |

### public cache(): * source

#### Return:

*

### public changeParent(newParent: *) source

#### Params:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
state | * |  |

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

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

#### Params:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
newValue | * |  | the new state value

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

#### Params:

Name | Type | Attribute | Description
time | * |  |
newRoot | * |  |

### public dispatchUpdate(action: *) source

Intended for use by update() and replaying actions.

#### Params:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
path | * |  |

#### Return:

*

### public getChild(name: *): * source

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

#### Params:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
callback | * |  |

### public obsoleteChildren() source

### public obsoleteTree(callback: *) source

Marks the entire subtree as inactive, aka dead.

#### Params:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
prev | * |  |

### public shader(state: *): * source

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

#### Params:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
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:

Name | Type | Attribute | Description
parentWillUnshadow | boolean |  | `true` when parent property is unshadowing.