Table of Contents generated with DocToc

ObservableSet

ObservableSet is an observable wrapper over a JavaScript Set. It allows Twist to detect when the contents of the set changes, so that reactivity works as expected.

NOTE: ObservableSet is not currently iterable from JavaScript, unlike a Set - this capability will be added in future.

Constructor

The constructor can optionally be supplied a Set, or an Iterable object:

import { ObservableSet } from '@twist/core';

var set1 = new ObservableSet;
console.log(set1.size); // 0

var set2 = new ObservableSet([ 1, 2, 3, 3 ]);
console.log(set2.size); // 3 (sets can't contain duplicates)

var set3 = new ObservableSet(new Set([ 1, 2 ]));
console.log(set3.size); // 2

Properties

Property Description
length Alias for size
size Returns the number of elements in the set

Methods

Method Description
add() Adds an element to the set
clear() Removes all elements from the set
delete() Deletes the element from the set
entries() Returns a new Iterator object that contains the elements in the set
forEach() Iterates over the elements in the set
has() Returns a Boolean indicating the presence of an element in the set
keys() Alias for values()
values() Returns a new Iterator object that contains the elements in the set

results matching ""

    No results matching ""