jwidget/IBindableSet

Consumption

import IBindableSet from "jwidget/IBindableSet";

Default export#

Hierarchy#

Description#

T
Value type.

Extension of DestroyableReadonlyBindableSet with modification methods.

Fields#

silent (inherited from ReadonlyBindableSet)#

readonly silent: boolean

Checks if this collection never dispatches messages. This knowledge may help you do certain code optimizations.
size (inherited from ReadonlyBindableSet)#

readonly size: Bindable<number>

Property containing number of values in the set.
native (inherited from ReadonlyBindableSet)#

readonly native: ReadonlySet<T>

Native set - internal collection representation.
onSplice (inherited from ReadonlyBindableSet)#

readonly onSplice: Listenable<IBindableSet.SpliceResult<T>>

Value are deleted from the set and/or values are added to the set.
onClear (inherited from ReadonlyBindableSet)#

readonly onClear: Listenable<ReadonlySet<T>>

The set is cleared.
onChange (inherited from ReadonlyBindableSet)#

readonly onChange: Listenable<void>

The set is changed. Dispatched right after any another message.

Methods#

ownValues#

(): this

Makes this set an owner of its values, which means that its values are alive as long as they are present in this set. A value is destroyed when it leaves the set, and all values are destroyed on the set destruction.

add#

(value: T): boolean

Value
Value to add.
returns
The value is added successfully. Returns false if the value is already present.

Adds a value to the set if one is absent and dispatches onSplice message.

addAll#

(values: Iterable<T>): ReadonlySet<T>

values
Values to add.
returns
The truly added values. Never returns null or undefined.

Adds multiple values to the set, ones that are absent, and dispatches onSplice message.

delete#

(value: T): boolean

value
Value to delete.
returns
The value is deleted successfully. Returns false if the value is already absent.

Deletes a value from the set if one is present and dispatches a onSplice message.

deleteAll#

(values: Iterable<T>): ReadonlySet<T>

values
Values to delete.
returns
The truly deleted values. Never returns null or undefined.

Deletes multiple values from the set, ones that are present, and dispatches onSplice message.

clear#

(): ReadonlySet<T>

returns
Old contents of the set. Never returns null or undefined.

Deletes all values from the set and dispatches onClear message.

splice#

(valuesToDelete: Iterable<T>, valuesToAdd: Iterable<T>): IBindableSet.SpliceResult<T>

valuesToDelete
Values to delete.
valuesToAdd
Values to add.
returns
Splice result. Never returns null or undefined.

Deletes and/or adds multiple values in the set granularly and dispatches onSplice message.

tryAddAll#

(values: Iterable<T>): ReadonlySet<T>

values
Values to add.
returns
The truly added values. If the call doesn't modify the set, returns undefined.

Adds multiple values to the set, ones that are absent, and dispatches onSplice message.

tryDeleteAll#

(values: Iterable<T>): ReadonlySet<T>

values
Values to delete.
returns
The truly deleted values. If the call doesn't modify the set, returns undefined.

Deletes multiple values from the set, ones that are present, and dispatches onSplice message.

tryClear#

(): ReadonlySet<T>

returns
Old contents of the set. If the call doesn't modify the set, returns undefined.

Deletes all set values and dispatches onClear message.

trySplice#

(valuesToDelete: Iterable<T>, valuesToAdd: Iterable<T>): IBindableSet.SpliceResult<T>

valuesToDelete
Values to delete.
valuesToAdd
Values to add.
returns
Splice result. If the call doesn't modify the set, returns undefined.

Deletes and/or adds multiple values in the set granularly and dispatches onSplice message.

performSplice#

(newContents: Iterable<T>)

newContents
New set contents.

Adjusts the set contents to newContents using detectSplice and splice methods.

destroy (inherited from Destroyable)#

(): void

Class destructor. You must override it in a subclass and call this method explicitly from outside, because JavaScript doesn't support automatic class destructor calling.

const object = new MyClass();

// ...

// When the object is not needed anymore, destroy it.
object.destroy();

Alternatively (and optimally), you should use own method to aggregate this object in another one.

[Symbol.iterator] (inherited from ReadonlyBindableSet)#

(): IterableIterator<T>

returns
Set iterator.
has (inherited from ReadonlyBindableSet)#

(value: T): boolean

forEach (inherited from ReadonlyBindableSet)#

(callback: (value: T) => void): void

callback
Callback function.

Iterates through the collection items. Calls the specified function for all values.

detectSplice (inherited from ReadonlyBindableSet)#

(newContents: Iterable<T>): IBindableSet.SpliceParams<T>

newContents
New set contents.
returns
splice method arguments. If no method call required, returns undefined.

Detects splice method arguments to adjust the set contents to newContents. Determines values to be deleted and added.

own (inherited from IClass)#

<T extends Destroyable>(obj: T): T

obj
Object to aggregate.
returns
obj

Aggregates the object. It means that the specified object is automatically destroyed on this object destruction. The aggregated objects are destroyed in reverse order. Returns obj object, which makes it easy to use in field definition:

private selected = this.own(new Property(false));
owning (inherited from IClass)#

(obj: Destroyable): this

obj
Object to aggregate.
returns
this

The same as own, but returns this, which makes it easy to use in object instantiation:

const items = new BindableArray().ownValues();
return new Panel(items).owning(items);

IBindableSet.SpliceParams#

T
Value type.

IBindableSet.splice method arguments. Result of detectSplice method.

valuesToDelete#

readonly valuesToDelete: Iterable<T>

Values to delete.
valuesToAdd#

readonly valuesToAdd: Iterable<T>

Values to add.

IBindableSet.SpliceResult#

T
Value type.

IBindableSet.splice method result.

deletedValues#

readonly deletedValues: ReadonlySet<T>

Deleted values.
addedValues#

readonly addedValues: ReadonlySet<T>

Added values.