gradum-kit - v0.1.0
    Preparing search index...

    Class StatefulReifect<State, ClassType>

    StatefulReifect

    A class to manage and apply dynamic state-based properties, styles, classes, and transitions to a set of objects.

    Type Parameters

    • State extends string | number | symbol = any

      The type of the reifier's states.

    • ClassType extends object = object

      The object type this reifier will be applied to.

    Hierarchy (View Summary)

    Index
    fields: readonly ["properties", "classes", "styles", "replaceWith"] = ...

    The categories of value a reifect can apply to an object.

    knownFields: Set<string> = ...

    Property names the reifect handles itself. Anything else given in its configuration is treated as a property to set on the attached objects.

    chainableStyleFields: Set<string> = ...

    Style properties that several reifects may contribute to at once, and so are recombined rather than overwritten when more than one reifect is attached to the same object.

    timeRegex: RegExp = ...

    Matches a CSS duration, capturing the number and its unit, so durations given as strings can be read back as seconds.

    attachedObjectsData: WeakMap<ClassType, ReifectObjectData<State, ClassType>> = ...

    Per-object state, keyed weakly so attaching a reifect does not keep an object alive.

    attachedObjects: GradumNodeList<ClassType> = ...

    Every object this reifect is attached to, in attachment order. Objects dropped elsewhere disappear from the list on their own.

    • get states(): State[]

      Returns State[]

      All possible states.

    • set states(states: object | State[]): void

      Parameters

      • states: object | State[]

      Returns void

    • set propertiesEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • set classesEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • set stylesEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • set replacedWithEnabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • set enabled(value: boolean): void

      Parameters

      • value: boolean

      Returns void

    • get properties(): PartialRecord<
          State,
          ReifectInterpolator<PartialRecord<keyof ClassType, any>, ClassType>,
      >

      Returns PartialRecord<
          State,
          ReifectInterpolator<PartialRecord<keyof ClassType, any>, ClassType>,
      >

    • set properties(
          value: PropertyConfig<
              PartialRecord<keyof ClassType, any>,
              State,
              ClassType,
          >,
      ): void

      Parameters

      Returns void

      The properties to be assigned to the objects. It could take:

      • A record of {key: value} pairs.
      • A record of {state: {key: value} pairs or an interpolation function that would return a record of {key: value} pairs}.
      • An interpolation function that would return a record of {key: value} pairs based on the state value. The interpolation function would take as arguments:
      • state: State: the state being applied to the object(s). Only passed to the callback function if it is defined for the whole field (and not for a specific state).
      • index: number: the index of the object in the applied list.
      • total: number: the total number of objects in the applied list.
      • object: ClassType: the object itself.
    • Returns PartialRecord<State, ReifectInterpolator<StylesType, ClassType>>

    • set styles(value: PropertyConfig<StylesType, State, ClassType>): void

      Returns void

      The styles to be assigned to the objects (only if they are eligible elements). It could take:

      • A record of {CSS property: value} pairs.
      • A record of {state: {CSS property: value} pairs or an interpolation function that would return a record of {key: value} pairs}.
      • An interpolation function that would return a record of {key: value} pairs based on the state value. The interpolation function would take as arguments:
      • state: State: the state being applied to the object(s). Only passed to the callback function if it is defined for the whole field (and not for a specific state).
      • index: number: the index of the object in the applied list.
      • total: number: the total number of objects in the applied list.
      • object: ClassType: the object itself.
    • get classes(): PartialRecord<
          State,
          ReifectInterpolator<string | string[], ClassType>,
      >

      Returns PartialRecord<State, ReifectInterpolator<string | string[], ClassType>>

    • set classes(value: PropertyConfig<string | string[], State, ClassType>): void

      Parameters

      Returns void

      The classes to be assigned to the objects (only if they are eligible elements). It could take:

      • A string of space-separated classes.
      • An array of classes.
      • A record of {state: space-separated class string, array of classes, or an interpolation function that would return any of the latter}.
      • An interpolation function that would return a string of space-separated classes or an array of classes based on the state value. The interpolation function would take as arguments:
      • state: State: the state being applied to the object(s). Only passed to the callback function if it is defined for the whole field (and not for a specific state).
      • index: number: the index of the object in the applied list.
      • total: number: the total number of objects in the applied list.
      • object: ClassType: the object itself.
    • get replaceWith(): PartialRecord<
          State,
          ReifectInterpolator<ClassType, ClassType>,
      >

      Returns PartialRecord<State, ReifectInterpolator<ClassType, ClassType>>

    • set replaceWith(value: PropertyConfig<ClassType, State, ClassType>): void

      Parameters

      Returns void

      The object that should replace (in the DOM as well if eligible) the attached objects. It could take:

      • The object to be replaced with.
      • A record of {state: object to be replaced with, or an interpolation function that would return an object to be replaced with}.
      • An interpolation function that would return the object to be replaced with based on the state value. The interpolation function would take as arguments:
      • state: State: the state being applied to the object(s). Only passed to the callback function if it is defined for the whole field (and not for a specific state).
      • index: number: the index of the object in the applied list.
      • total: number: the total number of objects in the applied list.
      • object: ClassType: the object itself.
    • Parameters

      Returns this

    • Parameters

      Returns this

    • Function

      attach

      Parameters

      • object: ClassType

        The object to attach.

      • OptionalonSwitch: ReifectOnSwitchCallback<State, ClassType>

        Optional callback fired when the reifier is applied to the object. The callback takes as parameters:

        • state: State: The state being applied to the object.
        • index: number: the index of the object in the applied list.
        • total: number: the total number of objects in the applied list.
        • object: ClassType: the object itself.
      • Optionalindex: number

        Optional index to specify the position at which to insert the object in the reifier's attached list.

      Returns this

      • The reifier itself, for method chaining.

      Attaches an object to the reifier.

    • Parameters

      Returns this

    • Parameters

      • ...objectsAndIndex: [...ClassType[], number]

      Returns this

    • Parameters

      Returns this

    • Parameters

      Returns this

    • Parameters

      Returns this

    • Function

      detach

      Parameters

      • ...objects: ClassType[]

        The objects to detach.

      Returns this

      • The reifier itself, for method chaining.

      Detaches one or more objects from the reifier.

    • Protected Function

      attachObject

      Parameters

      • object: ClassType

        The object to attach

      • OptionalonSwitch: ReifectOnSwitchCallback<State, ClassType>

        Optional callback fired when the reifier is applied to the object. The callback takes as parameters:

        • state: State: The state being applied to the object.
        • index: number: the index of the object in the applied list.
        • total: number: the total number of objects in the applied list.
        • object: ClassType: the object itself.
      • Optionalindex: number

        Optional index to specify the position at which to insert the object in the reifier's attached list.

      Returns ReifectObjectData<State, ClassType>

      • The created data entry.

      Function used to generate a data entry for the given object, and add it to the attached list at the provided index (if any).

    • Protected Function

      detachObject

      Parameters

      Returns void

      Stop tracking an object, so the reifect no longer applies to it. Does nothing if the object was never attached.

    • Function

      getObject

      Parameters

      Returns ClassType

      The corresponding object, or null if was garbage collected.

      Retrieves the object attached to the given data entry.

    • Function

      stateOf

      Parameters

      • object: ClassType

        The object to determine the state for.

      Returns State

      • The current state of the reifect or undefined if not determinable.

      Determine the current state of the reifect on the provided object.

    • Protected Function

      parseState

      Parameters

      • value: boolean | State

        The value to parse.

      Returns State

      The parsed value, or null if the boolean could not be parsed.

      Parses a boolean into the corresponding state value.

    • Function

      getObjectEnabledState

      Parameters

      • object: ClassType

        The object to get the state of.

      Returns ReifectEnabledObject

      • The corresponding enabled state.

      Returns the enabled value corresponding to the provided object for this reifier.

    • Function

      unapply

      Parameters

      Returns this

      Itself, allowing for method chaining.

      Remove everything this reifect applied, returning the objects to how they were before.

    • Function

      reloadFor

      Parameters

      • object: ClassType

        The element to apply the string to.

      Returns this

      Itself for method chaining.

      Generates the transition CSS string for the provided transition with the correct interpolation information.

    • Parameters

      • object: ClassType
      • applyStylesInstantly: boolean = false

      Returns void

    • Parameters

      • object: ClassType
      • applyStylesInstantly: boolean = false

      Returns void

    • Returns void

    • Parameters

      Returns void

    • Parameters

      Returns void

    • Returns void

    • Parameters

      Returns void

    • Parameters

      Returns void

    • Returns void

    • Parameters

      Returns void

    • Parameters

      Returns void

    • Returns void

    • Parameters

      • object: ClassType
      • Optionalstate: State
      • applyStylesInstantly: boolean = false

      Returns void

    • Parameters

      • object: ClassType
      • applyStylesInstantly: boolean = false

      Returns void

    • Returns void

    • Parameters

      Returns Partial<Record<string, string>>

    • Protected Function

      filterEnabledObjects

      Parameters

      Returns boolean

      Whether the reifect applies to this object.

      Decide whether an object should be acted on, warning when one is skipped because the reifect was disabled for it. Override to change which objects a reifect reaches.

    • Protected Function

      processRawProperties

      Parameters

      Returns void

      Resolve an object's per-state values from the reifect's configuration and cache them, so interpolated values are computed once instead of on every state switch. The resolution runs inside an effect, so the cache refreshes by itself when a value it read changes.

    • Parameters

      • states: object | State[]

      Returns State[]