turbodombuilder - v0.9.22
    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 TurboDataBlock<DataType, KeyType, IdType> = TurboDataBlock<DataType, KeyType, IdType>

      The structure of each data block.

    Implements

    Index

    Constructors

    Properties

    isDataBlocksArray: boolean = false
    handlers: Map<
        string,
        TurboHandler<
            TurboModel<
                any,
                any,
                any,
                "map"
                | "array",
                TurboDataBlock<any, any, any, any, any>,
            >,
        >,
    >

    Map of MVC handlers bound to this model.

    keyChangedCallback: Delegate<
        (
            keyName: KeyType,
            blockKey: MvcBlockKeyType<BlocksType>,
            ...args: any[],
        ) => void,
    >

    Delegate triggered when a key changes.

    Accessors

    • get block(): BlockType

      Returns BlockType

      The default block.

    • set block(value: BlockType): void

      Parameters

      Returns void

    • 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

    • set enabledCallbacks(value: boolean): void

      Parameters

      • value: boolean

      Returns void

      Whether callbacks are enabled or not.

    Methods

    • Function

      setBlock

      Parameters

      Returns void

      Creates and sets a data block at the specified key.

    • Function

      hasBlock

      Parameters

      Returns boolean

      • Whether the block exists or not.

      Check if a block exists at the given key.

    • Function

      addBlock

      Parameters

      Returns void

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

    • Function

      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.

    • Function

      setData

      Parameters

      Returns void

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

    • Function

      hasData

      Parameters

      Returns boolean

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

    • Function

      getSize

      Parameters

      Returns number

      The size.

      Returns the size of the specified block.

    • Function

      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.

    • Function

      fireBlockCallback

      Parameters

      Returns void

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

    • Function

      initialize

      Parameters

      Returns void

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

    • Function

      clear

      Parameters

      Returns void

      Clears the block data at the given key.

    • Function

      isValidBlockKey

      Parameters

      Returns boolean

      True if valid, false otherwise.

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

    • Function

      getAllBlockIds

      Returns IdType[]

      Array of IDs.

      Retrieves all block (data) IDs in the model.

    • Function

      getAllValues

      Parameters

      Returns unknown[]

      Array of values.

      Retrieves all values across block(s).

    • Function

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

    • Function

      addHandler

      Parameters

      Returns void

      Registers a TurboHandler for the given key.