import SetFilterer, {startFilteringSet} from "jwidget/collection/SetFilterer";
SetFilterer binds one set to another, filling it with values of the source set a callback function returns a truthy value for.
const source = new BindableSet([1, 2, 3]); const filterer = new SetFilterer(source, x => x % 2 === 1); const target = filterer.target; expect(Array.from(target.native).sort()).eql([1, 3]); // Target collection is automatically synchronized with the original collection. source.addAll([4, 5, 6]); expect(Array.from(target.native).sort()).eql([1, 3, 5]); // Destroy the filterer to stop synchronization. filterer.destroy();
You can pass target set in a config option:
const source = new BindableSet([1, 2, 3]); const target = new BindableSet<number>(); const filterer = new SetFilterer(source, x => x % 2 === 1, {target});
If you want to filter the values into a new set, use shorthand function startFilteringSet instead:
const source = new BindableSet([1, 2, 3]); const target = startFilteringSet(source, x => x % 2 === 1); // Destroy the target array to stop synchronization. target.destroy();
new SetFilterer<T>(source: ReadonlyBindableSet<T>, test: (value: T) => boolean, config?: SetFilterer.Config<T>)
readonly source: ReadonlyBindableSet<T>
readonly target: ReadonlyBindableSet<T>
(): void
Class destructor invocation method. Destroys all aggregated objects and calls destroyObject method. You must 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 inside another one.
protected (): void
Class destructor implementation. Called in destroy method after destruction of all aggregated objects.
The logic of class instance destruction should usually be implemented here. If you override this method,
remember to call super.destroyObject()
at the end of the method:
destroyObject() { // Release resources ... // Call superclass destructor super.destroyObject(); }
<T extends Destroyable>(obj: T): T
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));
(obj: Destroyable): 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);
<T>(source: ReadonlyBindableSet<T>, test: (value: T) => boolean): DestroyableReadonlyBindableSet<T>