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

    Class Reifect<ClassType>

    Reifect

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

    Type Parameters

    • ClassType extends object = Node

      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<"default", 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 properties(): StatelessPropertyConfig<
          PartialRecord<keyof ClassType, any>,
          ClassType,
      >

      Returns StatelessPropertyConfig<PartialRecord<keyof ClassType, any>, ClassType>

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

      • A record of {key: value} pairs.
      • An interpolation function that would return a record of {key: value} pairs. The interpolation function would take as arguments:
      • 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.
    • set properties(
          value: StatelessPropertyConfig<
              PartialRecord<keyof ClassType, any>,
              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 StatelessPropertyConfig<StylesType, ClassType>

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

      • A record of {CSS property: value} pairs.
      • An interpolation function that would return a record of {key: value} pairs. The interpolation function would take as arguments:
      • 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.
    • set styles(value: StatelessPropertyConfig<StylesType, 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(): StatelessPropertyConfig<string | string[], ClassType>

      Returns StatelessPropertyConfig<string | string[], ClassType>

      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.
      • An interpolation function that would return a string of space-separated classes or an array of classes. The interpolation function would take as arguments:
      • 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.
    • set classes(value: StatelessPropertyConfig<string | string[], 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.
    • Returns StatelessPropertyConfig<ClassType, ClassType>

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

      • The object to be replaced with.
      • An interpolation function that would return the object to be replaced with. The interpolation function would take as arguments:
      • 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.
    • set replaceWith(value: StatelessPropertyConfig<ClassType, ClassType>): void

      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.
    • 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

    • Type Parameters

      • Type

      Parameters

      • currentConfig: any
      • newConfig: any

      Returns any

    • Parameters

      Returns this

    • Parameters

      Returns this

    • Function

      attach

      Parameters

      • object: ClassType

        The object to attach.

      • OptionalonSwitch: ReifectOnSwitchCallback<"default", 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<"default", 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<"default", 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

      stateOf

      Parameters

      • object: ClassType

        The object to determine the state for.

      Returns "default"

      • 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 | "default"

        The value to parse.

      Returns "default"

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

      Parses a boolean into the corresponding state value.

    • 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

    • Returns void

    • Parameters

      Returns void

    • Returns void

    • Parameters

      Returns void

    • Returns void

    • Parameters

      • object: ClassType
      • Optionalstate: "default"
      • applyStylesInstantly: boolean = false

      Returns void

    • Parameters

      • object: ClassType
      • applyStylesInstantly: boolean = false

      Returns void

    • Returns void

    • Parameters

      Returns void

    • 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 | "default"[]

      Returns "default"[]