ixfx
    Preparing search index...

    Interface ISetMutable<V>

    A Set which stores unique items determined by their value, rather than object reference (unlike the default JS Set). Create with Sets.mutable. Mutable.

    By default the JSON.stringify() representation is considered the 'key' for an object. Pass in a function to Sets.mutable to define your own way of creating keys for values. The principle should be that objects that you consider identical should have the same string key value.

    ISetMutable fires add, clear and delete events.

    const s = Sets.mutable();
    s.add(item); // Add one or more items. Items with same key are overriden.
    s.has(item); // Returns true if item value is present
    s.clear(); // Remove everything
    s.delete(item); // Delete item by value
    s.toArray(); // Returns values as an array
    s.values(); // Returns an iterator over values
    s.size; // Number of items stored in set
    // Data to add
    const people = [
    {name: `Barry`, city: `London`}
    {name: `Sally`, city: `Bristol`}
    ];

    // Create a set, defining how keys will be generated
    const set = Sets.mutable(person => {
    // Key person objects by name and city.
    // ie. Generated keys will be: `Barry-London`, `Sally-Bristol`
    return `${person.name}-${person.city}`
    });

    // Add list
    set.add(...people);

    // Demo:
    set.has({name:`Barry`, city:`Manchester`})); // False, key is different (Barry-Manchester)
    set.has({name:`Barry`, city:`London`})); // True, we have Barry-London as a key
    set.has(people[1]); // True, key of object is found (Sally-Bristol)

    Events

    set.addEventListener(`add`, ev => {
    console.log(`New item added: ${ev.value}`);
    });
    interface ISetMutable<V> {
        get isDisposed(): boolean;
        get size(): number;
        add(...values: readonly V[]): boolean;
        addEventListener<K extends keyof ValueSetEventMap<V>>(
            name: K,
            listener: (
                event: ValueSetEventMap<V>[K],
                sender: SimpleEventEmitter<ValueSetEventMap<V>>,
            ) => void,
        ): void;
        clear(): void;
        delete(value: V): boolean;
        dispose(): void;
        fireEvent<K extends keyof ValueSetEventMap<V>>(
            type: K,
            args: ValueSetEventMap<V>[K],
        ): void;
        has(value: V): boolean;
        removeEventListener<K extends keyof ValueSetEventMap<V>>(
            type: K,
            listener: (
                event: ValueSetEventMap<V>[K],
                sender: SimpleEventEmitter<ValueSetEventMap<V>>,
            ) => void,
        ): void;
        toArray(): readonly V[];
        values(): IterableIterator<V>;
    }

    Type Parameters

    • V

      Type of data stored

    Hierarchy (View Summary)

    Implemented by

    Index

    Accessors

    Methods

    • Add values to set. Corresponding keys will be generated according to the function provided to setMutable, or JSON.stringify by default.

      Parameters

      • ...values: readonly V[]

        Value(s) to add

      Returns boolean

      true if something new was added