turbodombuilder - v0.9.5
    Preparing search index...

    Class TurboModel<DataType, KeyType, IdType, BlocksType, BlockType>

    TurboModel

    A base class representing a model in MVC, which manages one or more data blocks and handles change propagation.

    Type Parameters

    • DataType = any

      The type of the data stored in each block.

    • KeyType extends string | number | symbol = any

      The type of the keys used to access data in blocks.

    • IdType extends string | number | symbol = any

      The type of the block IDs.

    • BlocksType extends "array" | "map" = "array" | "map"

      Whether data blocks are stored as an array or a map.

    • BlockType extends MvcDataBlock<DataType, IdType> = MvcDataBlock<DataType, IdType>

      The structure of each data block.

    Index

    Constructors

    Properties

    isDataBlocksArray: boolean = false
    handlers: Map<
        string,
        TurboHandler<
            TurboModel<any, any, any, "array" | "map", MvcDataBlock<any, any>>,
        >,
    >
    keyChangedCallback: Delegate<
        (
            keyName: KeyType,
            blockKey: MvcBlockKeyType<BlocksType>,
            ...args: any[],
        ) => void,
    >

    Delegate triggered when a key changes.

    Accessors

    • get data(): DataType

      Returns DataType

      The data of the default block.

    • set data(value: DataType): void

      Parameters

      Returns void

    • get dataId(): IdType

      Returns IdType

      The ID of the default block.

    • set dataId(value: IdType): void

      Parameters

      Returns void

    enabledCallbacks: any

    Whether callbacks are enabled or disabled.

    Methods

    • getData

      Parameters

      Returns unknown

      The value associated with the key, or null if not found.

      Retrieves the value associated with a given key in the specified block.

    • setData

      Parameters

      Returns void

      Sets the value for a given key in the specified block and triggers callbacks (if enabled).

    • getSize

      Parameters

      Returns number

      The size.

      Returns the size of the specified block.

    • setBlock

      Parameters

      • value: DataType

        The data to set.

      • Optionalid: IdType

        Optional block ID.

      • OptionalblockKey: MvcBlockKeyType<BlocksType> = ...

        The key of the block.

      • Optionalinitialize: boolean = true

        Whether to initialize the block after setting.

      Returns void

      Creates and sets a data block at the specified key.

    • hasBlock

      Parameters

      Returns boolean

      • Whether the block exists or not.

      Check if a block exists at the given key.

    • addBlock

      Parameters

      • value: DataType

        The block data.

      • Optionalid: IdType

        Optional block ID.

      • OptionalblockKey: MvcBlockKeyType<BlocksType>

        Block key (used for insertion in arrays).

      • Optionalinitialize: boolean = true

        Whether to initialize after adding.

      Returns void

      Adds a new block into the structure. Appends or inserts based on key if using array.

    • fireKeyChangedCallback

      Parameters

      • key: KeyType

        The key that changed.

      • OptionalblockKey: MvcBlockKeyType<BlocksType> = ...

        The block where the change occurred.

      • Optionaldeleted: boolean = false

        Whether the key was deleted.

      Returns void

      Fires the emitter's change callback for the given key in a block, passing it the data at the key's value.

    • fireCallback

      Parameters

      • key: string | KeyType

        The key to fire for.

      • ...args: any[]

        Additional arguments.

      Returns void

      Fires the emitter's change callback for the given key in the default blocks.

    • fireBlockCallback

      Parameters

      Returns void

      Fires the emitter's change callback for the given key in a specific block with custom arguments.

    • initialize

      Parameters

      Returns void

      Initializes the block at the given key, and triggers callbacks for all the keys in its data.

    • isValidBlockKey

      Parameters

      Returns boolean

      True if valid, false otherwise.

      Checks if the block key is a valid string or number.

    • getAllIds

      Returns IdType[]

      Array of IDs.

      Retrieves all block (data) IDs in the model.

    • getAllData

      Parameters

      Returns unknown[]

      Array of values.

      Retrieves all values across block(s).

    • getHandler

      Parameters

      • key: string

        The handler's key.

      Returns TurboHandler

      • The handler.

      Retrieves the attached MVC handler with the given key. By default, unless manually defined in the handler, if the element's class name is MyElement and the handler's class name is MyElementSomethingHandler, the key would be "something".

    • addHandler

      Parameters

      Returns void

      Registers a TurboHandler for the given key.