Skip to content

Class: ActiveSet<T> ​

Defined in: src/ActiveSet.ts:71

A Set of one model's instances - and nothing else can get in. Identity decides duplicates; with the unique option no two items may also share a key.

Emits itemsAdded, itemsRemoved and touched (also when an item changes), so it bubbles into a parent model like a nested model does. Create it with ActiveSet.create, or the set field option.

Extends ​

  • Set<T>

Type Parameters ​

T ​

T extends ActiveModel = ActiveModel

Constructors ​

Constructor ​

new ActiveSet<T>(values?): ActiveSet<T>

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:116

Parameters ​

values? ​

readonly T[] | null

Returns ​

ActiveSet<T>

Inherited from ​

Set<T>.constructor

Constructor ​

new ActiveSet<T>(iterable?): ActiveSet<T>

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:116

Parameters ​

iterable? ​

Iterable<T, any, any> | null

Returns ​

ActiveSet<T>

Inherited from ​

Set<T>.constructor

Properties ​

[toStringTag] ​

readonly [toStringTag]: string

Defined in: node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:145

Inherited from ​

Set.[toStringTag]


size ​

readonly size: number

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:112

Returns ​

the number of (unique) elements in Set.

Inherited from ​

Set.size


[species] ​

readonly static [species]: SetConstructor

Defined in: node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:322

Inherited from ​

Set.[species]

Accessors ​

model ​

Get Signature ​

get model(): typeof ActiveModel

Defined in: src/ActiveSet.ts:137

The model class this set accepts

Returns ​

typeof ActiveModel

Methods ​

[iterator]() ​

[iterator](): SetIterator<T>

Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:198

Iterates over values in the set.

Returns ​

SetIterator<T>

Inherited from ​

Set.[iterator]


add() ​

add(value): this

Defined in: src/ActiveSet.ts:152

Add one item (an instance, or plain data with coerce); adding what is already there is a no-op.

Parameters ​

value ​

T | RecursivePartialActiveModel<T>

Returns ​

this

Overrides ​

Set.add


addAll() ​

addAll(values): this

Defined in: src/ActiveSet.ts:157

Add several items; nothing is added if any is refused or takes a unique key another item holds.

Parameters ​

values ​

Iterable<T | RecursivePartialActiveModel<T>>

Returns ​

this


clear() ​

clear(): void

Defined in: src/ActiveSet.ts:233

Returns ​

void

Overrides ​

Set.clear


clone() ​

clone(): ActiveSet<T>

Defined in: src/ActiveSet.ts:271

A deep copy: every item is cloned; the options are kept.

Returns ​

ActiveSet<T>


delete() ​

delete(item): boolean

Defined in: src/ActiveSet.ts:209

Removes a specified value from the Set.

Parameters ​

item ​

T

Returns ​

boolean

Returns true if an element in the Set existed and has been removed, or false if the element does not exist.

Overrides ​

Set.delete


difference() ​

difference<U>(other): Set<T>

Defined in: node_modules/typescript/lib/lib.esnext.collection.d.ts:48

Type Parameters ​

U ​

U

Parameters ​

other ​

ReadonlySetLike<U>

Returns ​

Set<T>

a new Set containing all the elements in this Set which are not also in the argument.

Inherited from ​

Set.difference


entries() ​

entries(): SetIterator<[T, T]>

Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:203

Returns an iterable of [v,v] pairs for every value v in the set.

Returns ​

SetIterator<[T, T]>

Inherited from ​

Set.entries


forEach() ​

forEach(callbackfn, thisArg?): void

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:104

Executes a provided function once per each value in the Set object, in insertion order.

Parameters ​

callbackfn ​

(value, value2, set) => void

thisArg? ​

any

Returns ​

void

Inherited from ​

Set.forEach


getByKey() ​

getByKey(key): T | undefined

Defined in: src/ActiveSet.ts:253

The item that holds this unique key, in O(1) (needs the unique option)

Parameters ​

key ​

unknown

Returns ​

T | undefined


has() ​

has(value): boolean

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:108

Parameters ​

value ​

T

Returns ​

boolean

a boolean indicating whether an element with the specified value exists in the Set or not.

Inherited from ​

Set.has


hasKey() ​

hasKey(key): boolean

Defined in: src/ActiveSet.ts:258

Whether an item holds this unique key (needs the unique option)

Parameters ​

key ​

unknown

Returns ​

boolean


intersection() ​

intersection<U>(other): Set<T & U>

Defined in: node_modules/typescript/lib/lib.esnext.collection.d.ts:44

Type Parameters ​

U ​

U

Parameters ​

other ​

ReadonlySetLike<U>

Returns ​

Set<T & U>

a new Set containing all the elements which are both in this Set and in the argument.

Inherited from ​

Set.intersection


isDisjointFrom() ​

isDisjointFrom(other): boolean

Defined in: node_modules/typescript/lib/lib.esnext.collection.d.ts:64

Parameters ​

other ​

ReadonlySetLike<unknown>

Returns ​

boolean

a boolean indicating whether this Set has no elements in common with the argument.

Inherited from ​

Set.isDisjointFrom


isSubsetOf() ​

isSubsetOf(other): boolean

Defined in: node_modules/typescript/lib/lib.esnext.collection.d.ts:56

Parameters ​

other ​

ReadonlySetLike<unknown>

Returns ​

boolean

a boolean indicating whether all the elements in this Set are also in the argument.

Inherited from ​

Set.isSubsetOf


isSupersetOf() ​

isSupersetOf(other): boolean

Defined in: node_modules/typescript/lib/lib.esnext.collection.d.ts:60

Parameters ​

other ​

ReadonlySetLike<unknown>

Returns ​

boolean

a boolean indicating whether all the elements in the argument are also in this Set.

Inherited from ​

Set.isSupersetOf


keys() ​

keys(): SetIterator<T>

Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:208

Despite its name, returns an iterable of the values in the set.

Returns ​

SetIterator<T>

Inherited from ​

Set.keys


on() ​

on<E>(event, cb): () => void

Defined in: src/ActiveSet.ts:142

Subscribe to itemsAdded, itemsRemoved or touched on this set; returns an unsubscribe function.

Type Parameters ​

E ​

E extends EventType

Parameters ​

event ​

E

cb ​

EventListener<E>

Returns ​

() => void


once() ​

once<E>(event, cb): () => void

Defined in: src/ActiveSet.ts:147

Same as on, but the listener is removed after firing once.

Type Parameters ​

E ​

E extends EventType

Parameters ​

event ​

E

cb ​

EventListener<E>

Returns ​

() => void


symmetricDifference() ​

symmetricDifference<U>(other): Set<T | U>

Defined in: node_modules/typescript/lib/lib.esnext.collection.d.ts:52

Type Parameters ​

U ​

U

Parameters ​

other ​

ReadonlySetLike<U>

Returns ​

Set<T | U>

a new Set containing all the elements which are in either this Set or in the argument, but not in both.

Inherited from ​

Set.symmetricDifference


toJSON() ​

toJSON(): object[]

Defined in: src/ActiveSet.ts:281

The items as plain data, like JSON.stringify would produce

Returns ​

object[]


union() ​

union<U>(other): Set<T | U>

Defined in: node_modules/typescript/lib/lib.esnext.collection.d.ts:40

Type Parameters ​

U ​

U

Parameters ​

other ​

ReadonlySetLike<U>

Returns ​

Set<T | U>

a new Set containing all the elements in this Set and also all the elements in the argument.

Inherited from ​

Set.union


values() ​

values(): SetIterator<T>

Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:213

Returns an iterable of values in the set.

Returns ​

SetIterator<T>

Inherited from ​

Set.values


create() ​

static create<M>(this, model, items?, options?): ActiveSet<InstanceType<M>>

Defined in: src/ActiveSet.ts:77

Type Parameters ​

M ​

M extends typeof ActiveModel

Parameters ​

this ​

typeof ActiveSet

model ​

M

the only model class the set accepts

items? ​

Iterable<unknown> = []

initial items (instances or, with coerce, plain data)

options? ​

SetOptions<InstanceType<M>> = {}

unique key and coerce

Returns ​

ActiveSet<InstanceType<M>>


field() ​

static field<M>(this, model, options?): ContainerSpec<ActiveSet<InstanceType<M>>>

Defined in: src/ActiveSet.ts:108

Describe a set field for @ActiveField({ container }): an assigned array or Set becomes an ActiveSet of model, the default is an empty one.

Type Parameters ​

M ​

M extends typeof ActiveModel

Parameters ​

this ​

typeof ActiveSet

model ​

M

options? ​

SetOptions<InstanceType<M>> = {}

Returns ​

ContainerSpec<ActiveSet<InstanceType<M>>>

Example ​

ts
@ActiveField({ container: ActiveSet.field(Tag, { unique: 'name' }) }) tags!: ActiveSet<Tag>

on() ​

static on(event, cb): () => void

Defined in: src/ActiveSet.ts:127

Subscribe to an event on every set of this class.

Parameters ​

event ​

EventType

cb ​

ActiveModelHookListener

Returns ​

() => void


once() ​

static once(event, cb): () => void

Defined in: src/ActiveSet.ts:132

Same as on, but the listener is removed after firing once.

Parameters ​

event ​

EventType

cb ​

ActiveModelHookListener

Returns ​

() => void