Skip to main content

Slots class

📖 Description

The Slots class defines a collection that holds all the slots for a block. It is used in the builder part of a block implementation to denote the data slots for that block. There are four kinds of slots supported by the Slots class:

  • static: Static slots are fixed slots that are required for the functional operation of a block (for example, a string slot that holds the text value of a text input block);
  • dynamic: Dynamic slots are used for dynamic elements in a block (for example, slots that are created for each checkbox of a block that supports a customizable list of checkboxes);
  • feature: Feature slots are used for optional features of a block (for example, a slot that holds the score value of a block that supports an optional score feature);
  • meta: Meta slots are used to store metadata (for example, the time taken to answer a block).

🗃️ Fields


🏷️ all

Retrieves all the slots that are in the collection.

Type

Slot[]


🏷️ count

Retrieves the number of slots in the collection.

Type

number


🏷️ firstItem

Retrieves the first slot in the collection.

Type

Slot | undefined


🏷️ lastItem

Retrieves the last slot in the collection.

Type

Slot | undefined

▶️ Methods


🔧 clean

Removes all the slots from the slots collection.

Signature

clean(kind?: "static" | "dynamic" | "feature" | "meta", ...exclude: Slot[]): void

Parameters

NameTypeOptionalDescription
kind"static" | "dynamic" | "feature" | "meta"YesOptional kind that specifies the kind of slots to remove.
...excludeSlot[]YesSpecifies the slots that you want to keep.

🔧 delete

Deletes a slot from the slots collection.

Signature

delete<T extends Slot>(
referenceOrId: string,
kind?: "static" | "dynamic" | "feature" | "meta"
): T | undefined

Parameters

NameTypeOptionalDescription
referenceOrIdstringNoSpecifies the reference or the identifier of the slot.
kind"static" | "dynamic" | "feature" | "meta"YesOptional kind to narrow the scope of the operation.

Return value

Returns the deleted Slot instance or undefined if the slot was not found.


🔧 deprecate

Deprecates a slot. This removes a slot from the slots collection and is used when a new version of a block needs to remove slots that were created by an earlier version of the block.

Signature

deprecate<T extends Slot>(
referenceOrId: string,
kind?: "static" | "dynamic" | "feature" | "meta"
): T | undefined

Parameters

NameTypeOptionalDescription
referenceOrIdstringNoSpecifies the reference or the identifier of the slot.
kind"static" | "dynamic" | "feature" | "meta"YesOptional kind to narrow the scope of the operation.

Return value

Returns the deprecated Slot instance or undefined if the slot was not found.


🔧 dynamic

Creates a new dynamic slot. Dynamic slots are used for dynamic elements in a block (for example, slots that are created for each checkbox of a block that supports a customizable list of checkboxes).

Signature

dynamic<T extends Slot>(properties: ISlotProperties): T

Parameters

NameTypeOptionalDescription
propertiesISlotPropertiesNoSpecifies the properties for the slot.

Return value

Returns a reference to the new Slot instance.


🔧 each

Iterates through all slots in the collection.

Signature

each(fn: (slot: Slot) => boolean | void): boolean

Parameters

NameTypeOptionalDescription
fn(slot: Slot) => boolean | voidNoFunction that is called for each slot in the collection. If you want to stop the iteration, you can return true from this function to do so.

Return value

Returns true if the iteration was stopped (break).


🔧 feature

Creates a new feature slot. Feature slots are used for optional features of a block (for example, a slot that holds the score value of a block that supports an optional score feature).

Signature

feature<T extends Slot>(properties: ISlotProperties): T

Parameters

NameTypeOptionalDescription
propertiesISlotPropertiesNoSpecifies the properties for the slot.

Return value

Returns a reference to the new Slot instance.


🔧 meta

Creates a new meta slot. Meta slots are used to store metadata (for example, the time taken to answer a block).

Signature

meta<T extends Slot>(properties: ISlotProperties): T

Parameters

NameTypeOptionalDescription
propertiesISlotPropertiesNoSpecifies the properties for the slot.

Return value

Returns a reference to the new Slot instance.


🔧 reverseEach

Iterates through all slots in the collection in reverse direction (starting with the last slot).

Signature

reverseEach(fn: (slot: Slot) => boolean | void): boolean

Parameters

NameTypeOptionalDescription
fn(slot: Slot) => boolean | voidNoFunction that is called for each slot in the collection. If you want to stop the iteration, you can return true from this function to do so.

Return value

Returns true if the iteration was stopped (break).


🔧 select

Selects a slot with the supplied reference or identifier.

Signature

select<T extends Slot>(
referenceOrId: string,
kind?: "static" | "dynamic" | "feature" | "meta"
): T | undefined

Parameters

NameTypeOptionalDescription
referenceOrIdstringNoSpecifies the reference or the identifier of the slot.
kind"static" | "dynamic" | "feature" | "meta"YesOptional kind to narrow the scope of the select operation.

Return value

Returns the Slot instance or undefined if the slot was not found.


🔧 selectByIdentifier

Selects a slot with the supplied identifier.

Signature

selectByIdentifier<T extends Slot>(id: string): T | undefined

Parameters

NameTypeOptionalDescription
idstringNoSpecifies the reference or the identifier of the slot.

Return value

Returns the Slot instance or undefined if the slot was not found.


🔧 sort

Sorts the slots based on the sequence number of the slots.

Signature

sort(): boolean

Return value

Returns true if the order of the slots has changed.


🔧 static

Creates a new static slot. Static slots are fixed slots that are required for the functional operation of a block (for example, a string slot that holds the text value of a text input block).

Signature

static<T extends Slot>(properties: ISlotProperties): T

Parameters

NameTypeOptionalDescription
propertiesISlotPropertiesNoSpecifies the properties for the slot.

Return value

Returns a reference to the new Slot instance.

Example

import { _, tripetto, slots, NodeBlock, Slots } from "@tripetto/builder";

@tripetto({
type: "node",
identifier: "example-block",
label: "Example",
icon: "data:image/svg+xml;base64,PHN2ZyAvPg=="
})
class ExampleBlock extends NodeBlock {
@slots
onSlots(): void {
// Let's define a static slot that holds a text value
this.slots.static({
type: Slots.Text,
reference: "text-value",
label: _("Example value")
});
}
}