ActiveList<T>

CLASS

ActiveList is a class which represents visual elements which have multiple pieces of content which can be active or inactive.

The ActiveList can be used to implement multiple types of components:

  1. A tabs component for which one tab can be active at a time.
  2. A carrousel component: the user sees single slide, which will autoPlay to the next slide automatically.
  3. A dropdown menu with one active menu item.
  4. A accordion component from which the user can open multiple items at once.
  5. A list the user can sort and move around.
  6. Etc etc

Another way of defining the ActiveList is that it is an array / list like data structure, because it supports things like insertion and removal.

ActiveList will make sure that when content is inserted, that the active content is not affected.

Since 1.0.0

Constructor

Creates an ActiveList based on the ActiveListConfig config.

You can also optionally provide an subscriber so you can get informed of the changes happening to the ActiveList.

Since 1.0.0

Signature

constructor(
config : ActiveListConfig<T> ,
): ActiveList<T>

Parameters

config: ActiveListConfig<T>

The initial configuration of the ActiveList.

subscriber: ActiveListSubscriber<T>

An optional subscriber which responds to changes in the ActiveList.

Throws

ActiveListAutoPlayDurationError autoPlay duration must be a positive number when defined

ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

Properties

  • active

    T []

    All value of the content which are currently considered active.

    Since 1.0.0

  • activeContents

    ActiveListContent<T> []

    All ActiveListContent which are currently considered active.

    Since 1.0.0

  • activeIndexes

    number []

    All indexes of which are currently considered active.

    Since 1.0.0

  • autoPlay

    ActiveListAutoPlay

    AutoPlay means that the ActiveList will move to the next content by itself after a duration.

    Contains whether or not the autoPlay is playing via isPlaying, the current duration via duration, and whether or not the autoPlay has been stopped before via hasBeenStoppedBefore

    Since 1.0.0

  • contents

    ActiveListContent<T> []

    The ActiveListContent instances which the ActiveList holds.

    Since 1.0.0

  • cooldown

    ActiveListCooldown

    A Cooldown is a time period in which all user made activations and deactivations are prevented / ignored. Activations and deactivations where the isUserInteraction is set to false always bypass the cooldown.

    The use-case is a cooldown can guarantees that animations are completed, before another is triggered.

    Contains whether or not the cooldown is active via isActive and the current duration via duration.

    Since 1.0.0

  • direction

    string

    The direction the ActiveList has previously moved to on activation or deactivation.

    Useful for when animating the ActiveList when wanting to animate differently based on the direction the content is activating towards.

    The direction is determined using the following rules for activation:

    1. When isCircular is false:

    a. If the lastActivatedIndex is -1 the direction is always next. The lastActivatedIndex is -1 when no item is active.

    b. If the lastActivatedIndex lies before the activated index the direction is next.

    c. If the lastActivatedIndex lies after the activated index the direction is previous.

    1. When isCircular is true,

    a. If the lastActivatedIndex is -1 the direction is always next. The lastActivatedIndex is -1 when no item is active.

    b. The direction is determined by checking which direction is the shortest path. If the shortest paths are tied, the direction will become next.

    Note: the direction is only changed upon activation and deactivation. Removing / inserting, moving and swapping do not affect the direction.

    Defaults to the value of the Config property direction.next.

    Since 1.0.0

  • hasActiveChangedAtLeastOnce

    boolean

    Whether or not the active item has changed at least once. Useful when you want to know if the ActiveList is still in its initial state.

    Note: when the initialize method of the Actions is called this boolean is reset.

    Since 1.0.0

  • history

    ActiveListEvent<T> []

    Contains the history of the changes in the contents array.

    Tracks 15 types of changes:

    1. INITIALIZED: fired when ActiveList is initialized.
    2. INSERTED: fired when an item is added.
    3. REMOVED: fired when an item is removed.
    4. REMOVED_MULTIPLE: fired when multiple items are removed with a predicate.
    5. ACTIVATED: fired when an item is activated.
    6. ACTIVATED_MULTIPLE: fired when multiple items are activated with a predicate.
    7. DEACTIVATED: fired when an item is deactivated.
    8. DEACTIVATED_MULTIPLE: fired when multiple items are deactivated with a predicate.
    9. SWAPPED: fired when an item is swapped.
    10. MOVED: fired when an item is moved.
    11. AUTO_PLAY_PLAYING: fired when play is called.
    12. AUTO_PLAY_PAUSED: fired when pause is called.
    13. AUTO_PLAY_STOPPED: fired when stop is called, or the autoPlay stops due to a condition.
    14. COOLDOWN_STARTED: fired when ActiveList goes into cooldown state
    15. COOLDOWN_ENDED: fired when ActiveList goes out of cooldown state

    Goes only as far back as configured in the Config property keepHistoryFor, to prevent an infinitely growing history. Note that by default no history is kept, as keepHistoryFor is zero by default.

    The last item in the history is the current active item. The further to the left the further in the past you go.

    This means that a history at index 0 is further in the past than an item at index 1.

    WARNING: all events store indexes, values and combinations thereof. The index of an item in the history may no longer be accurate, it is the index at the time of the event. Same goes for the value when it is an array of object, as it might have been mutated, the history items do not store copies of the values.

    Since 1.0.0

  • isCircular

    boolean

    Whether or not the content starts back at the beginning when the end of the content is reached, and whether the content should go to the end when moving left of the start.

    Defaults to false.

    Since 1.0.0

  • lastActivated

    T | null

    Which value from within an ActiveListContent was the last value which was activated.

    In other words: of all active values which value was activated the last chronologically.

    When nothing is activated in the ActiveList the value of lastActivated will be null.

    Since 1.0.0

  • lastActivatedContent

    ActiveListContent<T> | null

    Which ActiveListContent is the last ActiveListContent which was activated.

    In other words: of all active contents which content was activated the last chronologically.

    When nothing is activated in the ActiveList the value of lastActivatedContent will be null.

    Since 1.0.0

  • lastActivatedIndex

    number

    Which index of the contents array was the last index which was activated.

    In other words: of all active indexes which index was activated the last chronologically.

    When nothing is activated in the ActiveList the value of lastActivatedIndex will be -1.

    Since 1.0.0

  • lastDeactivated

    T | null

    Which value from within an ActiveListContent was the last value which was deactivated.

    When nothing was deactivated previously in the ActiveList the value of lastDeactivated will be null.

    Since 1.5.0

  • lastDeactivatedContent

    ActiveListContent<T> | null

    Which ActiveListContent is the last ActiveListContent which was deactivated.

    When nothing was deactivated previously in the ActiveList the value of lastDeactivatedContent will be null.

    Since 1.5.0

  • lastDeactivatedIndex

    number

    Which index of the contents array was the last index which was deactivated.

    When nothing was deactivated previously in the ActiveList the value of lastDeactivatedIndex will be -1.

    Since 1.5.0

  • maxActivationLimit

    number | false

    How many items can be active at the same time.

    When the value of limit is false there is no limit to the number of active items.

    Defaults to 1.

    Since 1.0.0

  • maxActivationLimitBehavior

    ActiveListMaxActivationLimitBehavior

    How the maxActivationLimit is enforced. In other words what the behavior should be when the limit is surpassed.

    The modes are strings which can be the following values:

    1. 'circular': the first item which was added will be removed so the last item can be added without violating the limit. This basically means that the first one in is the first one out.
    2. 'error': An error is thrown whenever the limit is surpassed, the error is called the ActiveListActivationLimitReachedError.
    3. 'ignore': Nothing happens when an item is added and the limit is reached. The item is simply not added, but no error is thrown.

    Defaults to 'circular'.

    Since 1.0.0

  • oppositeDirection

    string

    The opposite of the direction property of the ActiveList. If the direction is next the opposite direction is always previous and vice versa.

    Defaults to the value of the Config property direction.previous.

    Since 1.5.0

Methods

  • activate

    Activates the given item based on identity by comparing the item via a === check. When multiple items match on === only the first matching item is activated.

    If the item does not exist in the content array it will throw an error.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    activate(
    item : T ,
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    item: T

    The item to activate

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListItemNotFoundError item must be in the contents array based on === equality

    ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • activateByIndex

    Activates an item based on the index in the content array.

    If the index does not exist an error will be thrown.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    activateByIndex(
    index : number ,
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    index: number

    The index to activate

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListIndexOutOfBoundsError index cannot be out of bounds

    ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • activateByPredicate

    Activates all items that match the predicate.

    If no items match the predicate nothing happens.

    If multiple items were activated as a result of calling activateByPredicate they will be activated in order of appearance in the contents array.

    Items can also be deactivated if the maxActivationLimit is set to a number and the maxActivationLimitBehavior is set to "circular", if space needs to be made for the new activations.

    When maxActivationLimitBehavior is set to "error", all items that can be accommodated are activated, but when the limit is exceeded the activation stops. The subscribers are then informed of which items were activated, and then the error is thrown.

    Even through each item is activated sequentially, only one event is emitted, and one call is made to the subscribers, even if multiple items are activated and deactivated.

    Within the ActiveListActivatedMultipleEvent only the end activate / deactivate results are reported.

    With the activationOptions you can determine the effects on cooldown and autoPlay. When the cooldown is configured as a function, the last activated content will be the parameter to the cooldown function.

    Since 1.0.0

    Signature

    activateByPredicate(
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    predicate: ActiveListContentPredicate<T>

    A predicate function, when the predicate returns true it will activate that item.

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • activateFirst

    Activates the first item of the contents.

    If the contents are empty when activateFirst is called nothing will happen.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    activateFirst(
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • activateLast

    Activates the last item of the contents.

    If the contents are empty when activateLast is called nothing will happen.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    activateLast(
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • activateNext

    Activates the next item in the sequence based on the lastActivated ActiveListContent.

    If no lastActivated is present when activateNext is called the first element is activated.

    If the contents are empty when activateNext is called nothing will happen.

    When on the last position: if isCircular is true it will circle around and activate the first position. When isCircular is false it will stay on the last position and do nothing.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    activateNext(
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • activatePrevious

    Activates the previous item in the sequence based on the lastActivated ActiveListContent.

    If no lastActivated is present when activatePrevious is called the first element is activated.

    If the contents are empty when activatePrevious is called nothing will happen.

    When on the first position: if isCircular is true it will circle around and activate the last position. When isCircular is false it will stay on the first position and do nothing.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    activatePrevious(
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • configureAutoPlay

    Configures the autoPlay, when the autoPlay is null the autoPlay is stopped.

    Can be used to reconfigure the speed of the autoPlay after the ActiveList has been created.

    Note: calling configureAutoPlay will not set (reset) the hasBeenStoppedBefore to false` when called.

    Since 1.0.0

    Signature

    configureAutoPlay(
    autoPlayConfig : ActiveListAutoPlayConfig<T> | null
    ): void

    Parameters

    autoPlayConfig: ActiveListAutoPlayConfig<T> | null

    The new autoPlay configuration

    Throws

    ActiveListAutoPlayDurationError autoPlay duration must be a positive number when defined

  • deactivate

    Deactivates the given item based on identity by comparing the item via a === check. When multiple items match on === only the first matching item is activated.

    If the item does not exist in the content array it will throw an error.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    deactivate(
    item : T ,
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    item: T

    The item to deactivate

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListItemNotFoundError item must be in the contents array based on === equality

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • deactivateByIndex

    Deactivates an item based on the index in the content array.

    If the index does not exist an error will be thrown.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    deactivateByIndex(
    index : number ,
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    index: number

    The index to deactivate

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListIndexOutOfBoundsError index cannot be out of bounds

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • deactivateByPredicate

    Deactivates all items that match the predicate.

    If no items match the predicate nothing happens.

    If multiple items match they will be deactivated in order of appearance in the contents array. Only one call is made to the subscribers, even if multiple items are deactivated.

    With the activationOptions you can determine the effects on cooldown and autoPlay. When the cooldown is configured as a function, the last deactivated content will be the parameter to the cooldown function.

    Since 1.0.0

    Signature

    deactivateByPredicate(
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    predicate: ActiveListContentPredicate<T>

    A predicate function, when the predicate returns true it will deactivate that item.

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListCooldownDurationError cooldown duration must be a positive number when defined

  • getIndex

    Gets the index for a given item.

    If the item does not exist in the content array it will throw an error.

    Since 1.0.0

    Signature

    getIndex(
    item : T
    ): number

    Parameters

    item: T

    The item to get the index for.

    Returns

    The index of the given item.

    Throws

    ActiveListItemNotFoundError item must be in the contents array based on === equality

  • getLastIndex

    Returns the final index available in the contents array.

    Since 1.0.0

    Signature

    getLastIndex(): number

    Returns

    The last index of the contents array.

  • initialize

    Initializes the ActiveList based on the config provided. This can effectively reset the ActiveList when called, including the history, autoPlay and cooldown.

    Since 1.0.0

    Signature

    initialize( ): void

    Parameters

    config: ActiveListConfig<T>

    The new configuration which will override the old one

    Throws

    ActiveListAutoPlayDurationError autoPlay duration must be a positive number when defined

    ActiveListActivationLimitReachedError thrown when maxActivationLimit is exceeded, and maxActivationLimitBehavior is "error".

  • insertAtIndex

    Will add an item to the contents array, at the specified index.

    Note: insertAtIndex will not allow holes to be created, this means that the index can only be between 0 and contents.length. If you give it a larger or smaller index it will throw an error.

    Since 1.0.0

    Signature

    insertAtIndex(
    item : T ,
    index : number
    ): ActiveListContent<T>

    Parameters

    item: T

    The item to insert.

    index: number

    The index at which to insert the item.

    Returns

    The newly inserted item wrapped in an

    Throws

    ActiveListIndexOutOfBoundsError index cannot be out of bounds

  • insertByPredicate

    Will add an item at the position in the contents array when when the predicate returns true for the item and index.

    If no item matches the predicate nothing is inserted and null will be returned.

    The position to where the ActiveListContent is inserted can be altered by providing a mode:

    1. When the mode is 'at', the ActiveListContent is inserted to the position where the predicate matches. This is the default mode.
    2. When the mode is 'after', the ActiveListContent is inserted to after the position where the predicate matches.
    3. When the mode is 'before', the ActiveListContent is inserted to before the position where the predicate matches.

    Since 1.0.0

    Signature

    insertByPredicate(
    item : T ,
    ): ActiveListContent<T> | null

    Parameters

    item: T

    The item to insert.

    predicate: ActiveListContentPredicate<T>

    A predicate function, when the predicate returns true it will move the item to that position.

    options: ActiveListPredicateOptions

    The options for the predicate, when no options are provided the mode will default to "at".

  • isEmpty

    Whether or not the contents is an empty array.

    Since 1.0.0

    Signature

    isEmpty(): boolean
  • move

    Moves the item, to the position at index "to".

    It is possible to move the ActiveListContent to the last place by making the "to" index the length of the contents array.

    Note: if the active ActiveListContent is moved it will stay active, meaning that the lastActivatedIndex will get updated.

    Since 1.0.0

    Signature

    move(
    item : T ,
    to : number
    ): void

    Parameters

    item: T

    The item to move

    to: number

    The location the item needs to move "to".

    Throws

    ActiveListItemNotFoundError item must be in the contents array based on === equality

    ActiveListIndexOutOfBoundsError index cannot be out of bounds

  • moveByIndex

    Moves the ActiveListContent at index "from", to the position at index "to".

    It is possible to move the ActiveListContent to the last place by making the "to" index the length of the contents array.

    Note: if the active ActiveListContent is moved it will stay active, meaning that the lastActivatedIndex will get updated.

    Since 1.0.0

    Signature

    moveByIndex(
    from : number ,
    to : number
    ): void

    Parameters

    from: number

    The "from" index which needs to be moved

    to: number

    The location the from needs to move "to".

    Throws

    ActiveListIndexOutOfBoundsError index cannot be out of bounds

  • moveByIndexByPredicate

    Moves the ActiveListContent, at the index, to the position of the item for which the predicate returns true.

    If no item matches the predicate nothing is moved.

    The position to where the ActiveListContent moves can be altered by providing a mode:

    1. When the mode is 'at', the ActiveListContent is moved to the position where the predicate matches. This is the default mode.
    2. When the mode is 'after', the ActiveListContent is moved to after the position where the predicate matches.
    3. When the mode is 'before', the ActiveListContent is moved to before the position where the predicate matches.

    Since 1.0.0

    Signature

    moveByIndexByPredicate(
    index : number ,
    ): void

    Parameters

    index: number

    The index to move.

    predicate: ActiveListContentPredicate<T>

    A predicate function, when the predicate returns true it will move the item to that position.

    options: ActiveListPredicateOptions

    The options for the predicate, when no options are provided the mode will default to "at".

  • moveByPredicate

    Moves the ActiveListContent which matches the value of the item based on === equality. To the position of the item for which the predicate returns true.

    When multiple items match on === only the first matching item is moved.

    If no item matches the predicate nothing is moved.

    The position to where the ActiveListContent moves can be altered by providing a mode:

    1. When the mode is 'at', the ActiveListContent is moved to the position where the predicate matches. This is the default mode.
    2. When the mode is 'after', the ActiveListContent is moved to after the position where the predicate matches.
    3. When the mode is 'before', the ActiveListContent is moved to before the position where the predicate matches.

    Since 1.0.0

    Signature

    moveByPredicate(
    item : T ,
    ): void

    Parameters

    item: T

    The item to move.

    predicate: ActiveListContentPredicate<T>

    A predicate function, when the predicate returns true it will move the item to after that position.

    options: ActiveListPredicateOptions

    The options for the predicate, when no options are provided the mode will default to "at".

    Throws

    ActiveListItemNotFoundError item must be in the contents array based on === equality

  • pause

    When the ActiveList is playing it will pause the autoPlay.

    When paused, the current autoPlay duration is remember and resumed from that position, when play is called again.

    1. For example: when the duration is 1 second and the pause is called after 0.8 seconds, it will after play is called, take 2 seconds to go to the next content.

    Note: if the autoPlay is already paused calling pause again will do nothing, the time used for the remaining duration is based on the first pause.

    Since 1.0.0

    Signature

    pause(): void
  • play

    Will start playing the ActiveList based on the active autoPlayConfig. When autoPlayConfig is not defined nothing will happen when calling play.

    When there is no more content the playing will stop automatically.

    Note: autoPlay will only start when one or more contents are currently active. The reason for this is that the duration, is based on the ActiveList lastActivatedContent property. Whenever there are no more items to activate the autoPlay will stop.

    Since 1.0.0

    Signature

    play(): void

    Throws

    ActiveListAutoPlayDurationError autoPlay duration must be a positive number when defined

  • pop

    Removes the last item of the of the contents array.

    If you remove the lastDeactivated item it will be set to null.

    If the contents array at the time of the pop is empty undefined is returned.

    Since 1.0.0

    Signature

    pop(): undefined | T

    Returns

    The removed value, or undefined if the

  • push

    Will add an item to the end of the contents array.

    Since 1.0.0

    Signature

    push(
    item : T
    ): ActiveListContent<T>

    Parameters

    item: T

    The item to insert.

    Returns

    The newly inserted item wrapped in an

  • remove

    Removes the given item based on identity by comparing the item via a === check. When multiple items match on === only the first matching item is removed.

    If you remove the lastDeactivated item it will be set to null.

    If the item does not exist in the content array it will throw an error.

    Since 1.0.0

    Signature

    remove(
    item : T
    ): T

    Parameters

    item: T

    The item to remove

    Returns

    The removed item

    Throws

    ActiveListItemNotFoundError item must be in the contents array based on === equality

  • removeByIndex

    Will remove an item in the contents array, at the specified index.

    If you remove the lastDeactivated item it will be set to null.

    Throws an error if the index does not exist within the contents array.

    Since 1.0.0

    Signature

    removeByIndex(
    index : number
    ): T

    Parameters

    index: number

    The index at which to remove the item.

    Returns

    The removed value

    Throws

    ActiveListIndexOutOfBoundsError index cannot be out of bounds

  • removeByPredicate

    Will remove all items from the contents array for which the predicate based on the item and index returns true.

    If no item matches the predicate nothing is removed and an empty array will be returned.

    If you remove the lastDeactivated item it will be set to null.

    Since 1.0.0

    Signature

    removeByPredicate( ): T []

    Parameters

    predicate: ActiveListContentPredicate<T>

    A predicate function, when the predicate returns true it will remove the item.

    Returns

    The removed items.

  • shift

    Removes the first item of the contents array.

    If you remove the lastDeactivated item it will be set to null.

    If the contents array at the time of the shift is empty undefined is returned.

    Since 1.0.0

    Signature

    shift(): undefined | T

    Returns

    The removed value, or undefined if the

  • stop

    When the ActiveList is playing it will stop the autoPlay.

    By calling play again it is possible to restart the autoPlay. However the duration will behave in this scenario as it if was reset.

    For example: when the duration is 1 second and the stop is called after 0.8 seconds, it will after play is called, take 1 second to go to the next content.

    Since 1.0.0

    Signature

    stop(): void
  • subscribe

    Subscribe to changes of the ActiveList. The function you provide will get called whenever changes occur in the ActiveList.

    Returns an unsubscribe function which when called will unsubscribe from the ActiveList.

    Since 1.0.0

    Signature

    subscribe( ): UnsubscribeFunction

    Parameters

    subscriber: ActiveListSubscriber<T>

    The subscriber which responds to changes in the ActiveList.

    Returns

    A function which when called will unsubscribe from the ActiveList.

  • swap

    Swaps the ActiveListContent with item a, with the ActiveListContent with item b. Swaps the items based on identity by comparing the items via a === check. When multiple items match on === only the first matching item is swapped.

    Note: if the active ActiveListContent is swapped, it will stay active, it will only get a new position.

    Since 1.0.0

    Signature

    swap(
    a : T ,
    b : T
    ): void

    Parameters

    a: T

    The first item to swap.

    b: T

    The second item to swap.

    Throws

    ActiveListItemNotFoundError item must be in the contents array based on === equality

  • swapByIndex

    Swaps the ActiveListContent at index a, with the ActiveListContent at index b.

    Note: if the active ActiveListContent is swapped, it will stay active, it will only get a new position.

    Since 1.0.0

    Signature

    swapByIndex(
    a : number ,
    b : number
    ): void

    Parameters

    a: number

    The first index to swap.

    b: number

    The second index to swap.

    Throws

    ActiveListIndexOutOfBoundsError index cannot be out of bounds

  • toggle

    Toggles the given item based on identity by comparing the item via a === check. When multiple items match on === only the first matching item is activated.

    So when isActive is true and toggle is called, isActive will become false. When isActive is false and toggle is called, isActive will become true.

    If the item does not exist in the content array it will throw an error.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    toggle(
    item : T ,
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    item: T

    The item to toggle

    activationOptions: ActiveListActivationOptions<T>

    Throws

    ActiveListItemNotFoundError item must be in the contents array based on === equality

  • toggleByIndex

    When calling toggleByIndex it will flip the ActiveListContent which resides on the index isActive state .

    So when isActive is true and toggle is called, isActive will become false. When isActive is false and toggle is called, isActive will become true.

    If the index does not exist an error will be thrown.

    With the activationOptions you can determine the effects on cooldown and autoPlay.

    Since 1.0.0

    Signature

    toggleByIndex(
    index : number ,
    activationOptions : ActiveListActivationOptions<T>
    ): void

    Parameters

    index: number

    The index to activate

    activationOptions: ActiveListActivationOptions<T>

    The activation options

    Throws

    ActiveListIndexOutOfBoundsError index cannot be out of bounds

  • unshift

    Will add an item at the start of the contents array.

    Since 1.0.0

    Signature

    unshift(
    item : T
    ): ActiveListContent<T>

    Parameters

    item: T

    The item to insert.

    Returns

    The newly inserted item wrapped in an

  • unsubscribe

    Unsubscribe the subscriber so it no longer receives changes / updates of the state changes of the ActiveList.

    Since 1.0.0

    Signature

    unsubscribe( ): void

    Parameters

    subscriber: ActiveListSubscriber<T>

    The subscriber which you want to unsubscribe.

  • unsubscribeAll

    Unsubscribes all subscribers at once, all subscribers will no longer receives changes / updates of the state changes of the ActiveList.

    Since 1.5.0

    Signature

    unsubscribeAll(): void