Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aurumjs

Package Overview
Dependencies
Maintainers
0
Versions
244
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aurumjs - npm Package Compare versions

Comparing version 0.9.48 to 0.9.49

test/event_emitter.test.ts

2

package.json
{
"name": "aurumjs",
"version": "0.9.48",
"version": "0.9.49",
"main": "prebuilt/esnext/aurumjs.js",

@@ -5,0 +5,0 @@ "type": "module",

@@ -38,3 +38,3 @@ import { handleClass, handleStyle } from '../../nodes/rendering_helpers.js';

*/
export const defaultAttributes = ['id', 'name', 'draggable', 'tabindex', 'role', 'contenteditable', 'slot', 'title'];
export const defaultAttributes = ['id', 'name', 'draggable', 'tabIndex', 'role', 'contenteditable', 'slot', 'title'];
export function DomNodeCreator(nodeName, extraAttributes, extraEvents, extraLogic, svg = false) {

@@ -41,0 +41,0 @@ return function (props, children, api) {

@@ -250,5 +250,6 @@ import { CancellationToken } from '../utilities/cancellation_token.js';

else {
const cancel = state.listen(() => {
const token = new CancellationToken();
state.listen(() => {
if (state.value > 0) {
cancel();
token.cancel();
state.update(state.value - 1);

@@ -311,8 +312,9 @@ resolve(v);

else {
const unsub = onDequeue.subscribe(async () => {
const token = new CancellationToken();
onDequeue.subscribe(async () => {
if (queue[0] === v) {
unsub.cancel();
token.cancel();
return processItem();
}
});
}, token);
}

@@ -319,0 +321,0 @@ }

@@ -10,5 +10,5 @@ import { AurumServerInfo } from '../aurum_server/aurum_server_client.js';

readonly name: string;
listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): void;
listen(callback: Callback<T>, cancellationToken?: CancellationToken): void;
listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void;
awaitNextUpdate(cancellationToken?: CancellationToken): Promise<T>;

@@ -66,5 +66,5 @@ combine(otherSources: ReadOnlyDataSource<T>[], cancellationToken?: CancellationToken): DataSource<T>;

readonly name: string;
listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): void;
listen(callback: Callback<T>, cancellationToken?: CancellationToken): void;
listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void;
awaitNextUpdate(cancellationToken?: CancellationToken): Promise<T>;

@@ -206,4 +206,3 @@ withInitial(value: T): this;

*/
listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
private listenAndRepeatInternal;
listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -215,4 +214,3 @@ * Subscribes to the updates of the data stream

*/
listen(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
private listenInternal;
listen(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -224,3 +222,3 @@ * Subscribes to the updates of the data stream for a single update

*/
listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void;
transform<A, B = A, C = B, D = C, E = D, F = E, G = F, H = G, I = H, J = I, K = J>(operationA: DataSourceOperator<T, A>, operationB?: DataSourceOperator<A, B> | CancellationToken, operationC?: DataSourceOperator<B, C> | CancellationToken, operationD?: DataSourceOperator<C, D> | CancellationToken, operationE?: DataSourceOperator<D, E> | CancellationToken, operationF?: DataSourceOperator<E, F> | CancellationToken, operationG?: DataSourceOperator<F, G> | CancellationToken, operationH?: DataSourceOperator<G, H> | CancellationToken, operationI?: DataSourceOperator<H, I> | CancellationToken, operationJ?: DataSourceOperator<I, J> | CancellationToken, operationK?: DataSourceOperator<J, K> | CancellationToken, cancellationToken?: CancellationToken): DataSource<K>;

@@ -364,5 +362,5 @@ static fromAggregation<R, A>(sources: [ReadOnlyDataSource<A>], combinator: (first: A) => R, cancellationToken?: CancellationToken): DataSource<R>;

onItemsRemoved: EventEmitter<T[]>;
listenAndRepeat(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnce(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): void;
listen(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): void;
listenOnce(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): void;
awaitNextUpdate(cancellationToken?: CancellationToken): Promise<CollectionChange<T>>;

@@ -451,3 +449,3 @@ length: ReadOnlyDataSource<number>;

*/
listenAndRepeat(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): void;
/**

@@ -457,4 +455,4 @@ * Sends a reset signal followed by an append with all items signal. This will force all the views of this source the synchronize can be useful in case your views rely on non pure transformation functions.

repeatCurrentState(): void;
listen(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnce(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): void;
listenOnce(callback: Callback<CollectionChange<T>>, cancellationToken?: CancellationToken): void;
/**

@@ -605,7 +603,7 @@ * Applies the changes described in the colleciton change to the array. Useful for synchronizing array data sources over the network or workers by serializing the changes and sending them over

*/
listen(callback: Callback<MapChange<K, V>>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<MapChange<K, V>>, cancellationToken?: CancellationToken): void;
/**
* Same as listen but will immediately call the callback with the current value of each key
*/
listenAndRepeat(callback: Callback<MapChange<K, V>>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<MapChange<K, V>>, cancellationToken?: CancellationToken): void;
map<D>(mapper: (key: K, value: V, valueLifetimeToken: CancellationToken) => D, cancellation: CancellationToken): MapDataSource<K, D>;

@@ -619,7 +617,7 @@ toKeysArrayDataSource(cancellation: CancellationToken): ArrayDataSource<K>;

*/
listenOnKeyAndRepeat(key: K, callback: Callback<MapChange<K, V>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKeyAndRepeat(key: K, callback: Callback<MapChange<K, V>>, cancellationToken?: CancellationToken): void;
/**
* Listen to changes of a single key of the object
*/
listenOnKey(key: K, callback: Callback<MapChange<K, V>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKey(key: K, callback: Callback<MapChange<K, V>>, cancellationToken?: CancellationToken): void;
/**

@@ -681,6 +679,6 @@ * Returns all the keys of the object in the source

pick(key: K, cancellationToken?: CancellationToken): DataSource<boolean>;
listen(callback: Callback<SetChange<K>>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<SetChange<K>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKeyAndRepeat(key: K, callback: Callback<boolean>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKey(key: K, callback: Callback<boolean>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<SetChange<K>>, cancellationToken?: CancellationToken): void;
listenAndRepeat(callback: Callback<SetChange<K>>, cancellationToken?: CancellationToken): void;
listenOnKeyAndRepeat(key: K, callback: Callback<boolean>, cancellationToken?: CancellationToken): void;
listenOnKey(key: K, callback: Callback<boolean>, cancellationToken?: CancellationToken): void;
map<D>(mapper: (key: K) => D): ReadOnlyArrayDataSource<D>;

@@ -748,15 +746,15 @@ keys(): IterableIterator<K>;

*/
listen(callback: Callback<SetChange<K>>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<SetChange<K>>, cancellationToken?: CancellationToken): void;
/**
* Same as listen but will immediately call the callback with the current value of each key
*/
listenAndRepeat(callback: Callback<SetChange<K>>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<SetChange<K>>, cancellationToken?: CancellationToken): void;
/**
* Same as listenOnKey but will immediately call the callback with the current value first
*/
listenOnKeyAndRepeat(key: K, callback: Callback<boolean>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKeyAndRepeat(key: K, callback: Callback<boolean>, cancellationToken?: CancellationToken): void;
/**
* Listen to changes of a single key of the object
*/
listenOnKey(key: K, callback: Callback<boolean>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKey(key: K, callback: Callback<boolean>, cancellationToken?: CancellationToken): void;
toArrayDataSource(cancellationToken?: CancellationToken): ReadOnlyArrayDataSource<K>;

@@ -763,0 +761,0 @@ map<D>(mapper: (key: K) => D, cancellationToken?: CancellationToken): ReadOnlyArrayDataSource<D>;

@@ -78,3 +78,3 @@ import { AurumServerInfo } from '../aurum_server/aurum_server_client.js';

*/
listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -86,4 +86,3 @@ * alias for listenDownstream

*/
listen(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
private listenInternal;
listen(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -95,3 +94,3 @@ * Subscribes exclusively to updates of the data stream that occur due to an update flowing upstream

*/
listenUpstream(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenUpstream(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -103,3 +102,3 @@ * Subscribes exclusively to updates of the data stream that occur due to an update flowing upstream

*/
listenUpstreamAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenUpstreamAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -111,3 +110,3 @@ * Subscribes exclusively to one update of the data stream that occur due to an update flowing upstream

*/
listenUpstreamOnce(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenUpstreamOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -119,3 +118,3 @@ * Subscribes exclusively to updates of the data stream that occur due to an update flowing downstream

*/
listenDownstream(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenDownstream(callback: Callback<T>, cancellationToken?: CancellationToken): void;
downStreamToDataSource(cancellationToken?: CancellationToken): DataSource<T>;

@@ -185,3 +184,3 @@ /**

pipe(targetDataSource: DataSource<T>, cancellationToken?: CancellationToken): this;
listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void>;
listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -188,0 +187,0 @@ * Returns a promise that resolves when the next update occurs

@@ -188,3 +188,3 @@ import { syncDuplexDataSource } from '../aurum_server/aurum_server_client.js';

}
return this.listen(callback, cancellationToken);
this.listen(callback, cancellationToken);
}

@@ -198,7 +198,4 @@ /**

listen(callback, cancellationToken) {
return this.listenInternal(callback, cancellationToken);
this.updateDownstreamEvent.subscribe(callback, cancellationToken);
}
listenInternal(callback, cancellationToken) {
return this.updateDownstreamEvent.subscribe(callback, cancellationToken).cancel;
}
/**

@@ -211,3 +208,3 @@ * Subscribes exclusively to updates of the data stream that occur due to an update flowing upstream

listenUpstream(callback, cancellationToken) {
return this.updateUpstreamEvent.subscribe(callback, cancellationToken).cancel;
this.updateUpstreamEvent.subscribe(callback, cancellationToken);
}

@@ -224,3 +221,3 @@ /**

}
return this.updateUpstreamEvent.subscribe(callback, cancellationToken).cancel;
this.updateUpstreamEvent.subscribe(callback, cancellationToken);
}

@@ -234,3 +231,3 @@ /**

listenUpstreamOnce(callback, cancellationToken) {
return this.updateUpstreamEvent.subscribeOnce(callback, cancellationToken).cancel;
this.updateUpstreamEvent.subscribeOnce(callback, cancellationToken);
}

@@ -244,3 +241,3 @@ /**

listenDownstream(callback, cancellationToken) {
return this.updateDownstreamEvent.subscribe(callback, cancellationToken).cancel;
this.updateDownstreamEvent.subscribe(callback, cancellationToken);
}

@@ -341,3 +338,3 @@ downStreamToDataSource(cancellationToken) {

listenOnce(callback, cancellationToken) {
return this.updateDownstreamEvent.subscribeOnce(callback, cancellationToken).cancel;
this.updateDownstreamEvent.subscribeOnce(callback, cancellationToken);
}

@@ -344,0 +341,0 @@ /**

@@ -18,7 +18,7 @@ import { AurumServerInfo } from '../aurum_server/aurum_server_client.js';

pickDuplex<K extends keyof T>(key: K, cancellationToken?: CancellationToken): DuplexDataSource<T[K]>;
listen(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
listenAndRepeat(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
map<D>(mapper: (key: keyof T) => D): ArrayDataSource<D>;
listenOnKey<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, K>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKeyAndRepeat<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKey<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, K>>, cancellationToken?: CancellationToken): void;
listenOnKeyAndRepeat<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
keys(): string[];

@@ -68,3 +68,3 @@ values(): any;

*/
listen(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
map<D>(mapper: (key: keyof T, value: T[keyof T]) => D): ArrayDataSource<D>;

@@ -74,11 +74,11 @@ /**

*/
listenAndRepeat(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
/**
* Same as listenOnKey but will immediately call the callback with the current value first
*/
listenOnKeyAndRepeat<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKeyAndRepeat<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
/**
* Listen to changes of a single key of the object
*/
listenOnKey<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, K>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKey<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, K>>, cancellationToken?: CancellationToken): void;
/**

@@ -85,0 +85,0 @@ * Returns all the keys of the object in the source

@@ -141,3 +141,3 @@ import { syncObjectDataSource } from '../aurum_server/aurum_server_client.js';

listen(callback, cancellationToken) {
return this.updateEvent.subscribe(callback, cancellationToken).cancel;
this.updateEvent.subscribe(callback, cancellationToken);
}

@@ -170,3 +170,3 @@ map(mapper) {

listenAndRepeat(callback, cancellationToken) {
const c = this.updateEvent.subscribe(callback, cancellationToken).cancel;
this.updateEvent.subscribe(callback, cancellationToken);
for (const key in this.data) {

@@ -180,3 +180,2 @@ callback({

}
return c;
}

@@ -192,3 +191,3 @@ /**

});
return this.listenOnKey(key, callback, cancellationToken);
this.listenOnKey(key, callback, cancellationToken);
}

@@ -203,3 +202,3 @@ /**

const event = this.updateEventOnKey.get(key);
return event.subscribe(callback, cancellationToken).cancel;
event.subscribe(callback, cancellationToken);
}

@@ -206,0 +205,0 @@ /**

@@ -86,5 +86,5 @@ import { DataSourceOperator } from './operator_model.js';

getOutput(): DataSource<O>;
listen(callback: Callback<O>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<O>, cancellationToken?: CancellationToken): Callback<void>;
listenOnce(callback: Callback<O>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<O>, cancellationToken?: CancellationToken): void;
listenAndRepeat(callback: Callback<O>, cancellationToken?: CancellationToken): void;
listenOnce(callback: Callback<O>, cancellationToken?: CancellationToken): void;
awaitNextUpdate(cancellationToken?: CancellationToken): Promise<O>;

@@ -91,0 +91,0 @@ cancelAll(): void;

@@ -114,9 +114,9 @@ import { CancellationToken } from '../utilities/cancellation_token.js';

listen(callback, cancellationToken) {
return this.output.listen(callback, cancellationToken);
this.output.listen(callback, cancellationToken);
}
listenAndRepeat(callback, cancellationToken) {
return this.output.listenAndRepeat(callback, cancellationToken);
this.output.listenAndRepeat(callback, cancellationToken);
}
listenOnce(callback, cancellationToken) {
return this.output.listenOnce(callback, cancellationToken);
this.output.listenOnce(callback, cancellationToken);
}

@@ -123,0 +123,0 @@ awaitNextUpdate(cancellationToken) {

@@ -29,4 +29,4 @@ import { CancellationToken } from '../utilities/cancellation_token.js';

private watchHandleChange;
listen(callback: Callback<TreeChange<T>>, cancellationToken: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<TreeChange<T>>, cancellationToken: CancellationToken): Callback<void>;
listen(callback: Callback<TreeChange<T>>, cancellationToken: CancellationToken): void;
listenAndRepeat(callback: Callback<TreeChange<T>>, cancellationToken: CancellationToken): void;
private adaptNodeList;

@@ -33,0 +33,0 @@ private adaptNodeTree;

@@ -98,3 +98,3 @@ import { CancellationToken } from '../utilities/cancellation_token.js';

this.watch(cancellationToken);
return this.updateEvent.subscribe(callback, cancellationToken).cancel;
return this.updateEvent.subscribe(callback, cancellationToken);
}

@@ -110,3 +110,3 @@ listenAndRepeat(callback, cancellationToken) {

}
return this.listen(callback, cancellationToken);
this.listen(callback, cancellationToken);
}

@@ -113,0 +113,0 @@ adaptNodeList(nodes, token, nodeList = new ArrayDataSource()) {

@@ -13,2 +13,4 @@ import { Delegate, Callback } from './common.js';

static forever: CancellationToken;
static fromPromise<T>(promise: Promise<T>): CancellationToken;
static fromTimeout(time: number): CancellationToken;
hasCancellables(): boolean;

@@ -15,0 +17,0 @@ /**

@@ -13,2 +13,14 @@ export class CancellationToken {

static forever = new CancellationToken();
static fromPromise(promise) {
const token = new CancellationToken();
promise.then(() => {
token.cancel();
});
return token;
}
static fromTimeout(time) {
const token = new CancellationToken();
token.setTimeout(() => token.cancel(), time);
return token;
}
hasCancellables() {

@@ -136,3 +148,5 @@ return this.cancelables.length > 0;

this._isCancelled = true;
this.cancelables.forEach((c) => c());
for (const c of this.cancelables) {
c();
}
this.cancelables = undefined;

@@ -139,0 +153,0 @@ }

@@ -6,8 +6,2 @@ import { CancellationToken } from '../utilities/cancellation_token.js';

*/
export interface EventSubscriptionFacade {
cancel(): void;
}
/**
* @internal
*/
export type EventCallback<T> = (data: T) => void;

@@ -18,8 +12,5 @@ /**

export declare class EventEmitter<T> {
private static id;
private isFiring;
private onAfterFire;
/**
* Callback that if set is called when all subscriptions are removed
*/
onEmpty: Callback<void>;
private static leakWarningThreshold;

@@ -37,2 +28,3 @@ /**

private subscribeOnceChannel;
private subscribeCache;
constructor();

@@ -44,7 +36,7 @@ static fromAsyncIterator<T>(iterator: AsyncIterableIterator<T>): EventEmitter<T>;

*/
subscribe(callback: EventCallback<T>, cancellationToken?: CancellationToken): EventSubscriptionFacade;
subscribe(callback: EventCallback<T>, cancellationToken?: CancellationToken): void;
/**
* Subscribe to the event. The callback will be called when the event next fires an update after which the subscription is cancelled
*/
subscribeOnce(callback: Callback<T>, cancellationToken?: CancellationToken): EventSubscriptionFacade;
subscribeOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void;
/**

@@ -65,5 +57,7 @@ * Whether the event has any subscriptions

fire(data?: T): void;
private createSubscriptionOnce;
private createSubscription;
private cancelOnce;
private cancel;
}
//# sourceMappingURL=event_emitter.d.ts.map

@@ -5,8 +5,5 @@ /**

export class EventEmitter {
static id = 0;
isFiring;
onAfterFire;
/**
* Callback that if set is called when all subscriptions are removed
*/
onEmpty;
static leakWarningThreshold;

@@ -24,8 +21,9 @@ /**

get subscriptions() {
return this.subscribeChannel.length + this.subscribeOnceChannel.length;
return this.subscribeChannel.size + this.subscribeOnceChannel.length;
}
subscribeChannel;
subscribeOnceChannel;
subscribeCache;
constructor() {
this.subscribeChannel = [];
this.subscribeChannel = new Map();
this.subscribeOnceChannel = [];

@@ -123,7 +121,6 @@ this.onAfterFire = [];

subscribe(callback, cancellationToken) {
const { facade } = this.createSubscription(callback, this.subscribeChannel, cancellationToken);
if (EventEmitter.leakWarningThreshold && this.subscribeChannel.length > EventEmitter.leakWarningThreshold) {
console.warn(`Observable has ${this.subscribeChannel.length} subscriptions. This could potentially indicate a memory leak`);
this.createSubscription(callback, cancellationToken);
if (EventEmitter.leakWarningThreshold && this.subscribeChannel.size > EventEmitter.leakWarningThreshold) {
console.warn(`Observable has ${this.subscribeChannel.size} subscriptions. This could potentially indicate a memory leak`);
}
return facade;
}

@@ -134,7 +131,6 @@ /**

subscribeOnce(callback, cancellationToken) {
const { facade } = this.createSubscription(callback, this.subscribeOnceChannel, cancellationToken);
this.createSubscriptionOnce(callback, cancellationToken);
if (EventEmitter.leakWarningThreshold && this.subscribeOnceChannel.length > EventEmitter.leakWarningThreshold) {
console.warn(`Observable has ${this.subscribeOnceChannel.length} one time subscriptions. This could potentially indicate a memory leak`);
}
return facade;
}

@@ -152,11 +148,11 @@ /**

if (!this.isFiring) {
this.subscribeChannel.length = 0;
this.subscribeChannel.clear();
this.subscribeCache = undefined;
this.subscribeOnceChannel.length = 0;
this.onEmpty?.();
}
else {
this.onAfterFire.push(() => {
this.subscribeChannel.length = 0;
this.subscribeCache = undefined;
this.subscribeChannel.clear();
this.subscribeOnceChannel.length = 0;
this.onEmpty?.();
});

@@ -177,3 +173,3 @@ }

fire(data) {
const length = this.subscribeChannel.length;
const length = this.subscribeChannel.size;
const lengthOnce = this.subscribeOnceChannel.length;

@@ -186,5 +182,8 @@ if (length === 0 && lengthOnce === 0) {

let error = undefined;
if (this.subscribeCache === undefined) {
this.subscribeCache = Array.from(this.subscribeChannel.values());
}
for (let i = 0; i < length; i++) {
try {
this.subscribeChannel[i].callback(data);
this.subscribeCache[i](data);
}

@@ -199,3 +198,3 @@ catch (e) {

try {
this.subscribeOnceChannel[i].callback(data);
this.subscribeOnceChannel[i](data);
}

@@ -215,38 +214,59 @@ catch (e) {

}
createSubscription(callback, channel, cancellationToken) {
const that = this;
const subscription = {
callback
};
const facade = {
cancel() {
that.cancel(subscription, channel);
}
};
createSubscriptionOnce(callback, cancellationToken) {
if (cancellationToken !== undefined) {
cancellationToken.addCancellable(() => that.cancel(subscription, channel));
cancellationToken.addCancellable(() => this.cancelOnce(callback));
}
if (this.isFiring) {
this.onAfterFire.push(() => channel.push(subscription));
this.onAfterFire.push(() => this.subscribeOnceChannel.push(callback));
}
else {
channel.push(subscription);
this.subscribeOnceChannel.push(callback);
}
return { subscription, facade };
}
cancel(subscription, channel) {
let index = channel.indexOf(subscription);
if (index >= 0) {
if (!this.isFiring) {
channel.splice(index, 1);
if (!this.hasSubscriptions()) {
this.onEmpty?.();
createSubscription(callback, cancellationToken) {
const id = EventEmitter.id++;
if (cancellationToken !== undefined) {
cancellationToken.addCancellable(() => this.cancel(id));
}
if (this.isFiring) {
this.onAfterFire.push(() => {
if (this.subscribeCache === undefined) {
this.subscribeCache = Array.from(this.subscribeChannel.values());
}
this.subscribeCache.push(callback);
this.subscribeChannel.set(id, callback);
});
}
else {
if (this.subscribeCache === undefined) {
this.subscribeCache = Array.from(this.subscribeChannel.values());
}
this.subscribeCache.push(callback);
this.subscribeChannel.set(id, callback);
}
}
cancelOnce(subscription) {
if (!this.isFiring) {
let index = this.subscribeOnceChannel.indexOf(subscription);
if (index >= 0) {
this.subscribeOnceChannel.splice(index, 1);
}
else {
this.onAfterFire.push(() => this.cancel(subscription, channel));
this.onAfterFire.push(() => this.cancelOnce(subscription));
}
}
}
cancel(id) {
if (!this.isFiring) {
this.subscribeCache = undefined;
this.subscribeChannel.delete(id);
}
else {
this.onAfterFire.push(() => {
this.subscribeCache = undefined;
this.cancel(id);
});
}
}
}
//# sourceMappingURL=event_emitter.js.map

@@ -84,3 +84,3 @@ import { handleClass, handleStyle } from '../../nodes/rendering_helpers.js';

*/
export const defaultAttributes: string[] = ['id', 'name', 'draggable', 'tabindex', 'role', 'contenteditable', 'slot', 'title'];
export const defaultAttributes: string[] = ['id', 'name', 'draggable', 'tabIndex', 'role', 'contenteditable', 'slot', 'title'];

@@ -87,0 +87,0 @@ export function DomNodeCreator<T extends HTMLNodeProps<any>>(

@@ -274,5 +274,6 @@ import { CancellationToken } from '../utilities/cancellation_token.js';

} else {
const cancel = state.listen(() => {
const token = new CancellationToken();
state.listen(() => {
if (state.value > 0) {
cancel();
token.cancel();
state.update(state.value - 1);

@@ -337,8 +338,9 @@ resolve(v);

} else {
const unsub = onDequeue.subscribe(async () => {
const token = new CancellationToken();
onDequeue.subscribe(async () => {
if (queue[0] === v) {
unsub.cancel();
token.cancel();
return processItem();
}
});
}, token);
}

@@ -345,0 +347,0 @@ }

@@ -230,7 +230,7 @@ import { AurumServerInfo, syncDuplexDataSource } from '../aurum_server/aurum_server_client.js';

*/
public listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void> {
public listenAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): void {
if (this.primed) {
callback(this.value);
}
return this.listen(callback, cancellationToken);
this.listen(callback, cancellationToken);
}

@@ -244,10 +244,6 @@

*/
public listen(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void> {
return this.listenInternal(callback, cancellationToken);
public listen(callback: Callback<T>, cancellationToken?: CancellationToken): void {
this.updateDownstreamEvent.subscribe(callback, cancellationToken);
}
private listenInternal(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void> {
return this.updateDownstreamEvent.subscribe(callback, cancellationToken).cancel;
}
/**

@@ -259,4 +255,4 @@ * Subscribes exclusively to updates of the data stream that occur due to an update flowing upstream

*/
public listenUpstream(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void> {
return this.updateUpstreamEvent.subscribe(callback, cancellationToken).cancel;
public listenUpstream(callback: Callback<T>, cancellationToken?: CancellationToken): void {
this.updateUpstreamEvent.subscribe(callback, cancellationToken);
}

@@ -270,3 +266,3 @@

*/
public listenUpstreamAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void> {
public listenUpstreamAndRepeat(callback: Callback<T>, cancellationToken?: CancellationToken): void {
if (this.primed) {

@@ -276,3 +272,3 @@ callback(this.value);

return this.updateUpstreamEvent.subscribe(callback, cancellationToken).cancel;
this.updateUpstreamEvent.subscribe(callback, cancellationToken);
}

@@ -286,4 +282,4 @@

*/
public listenUpstreamOnce(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void> {
return this.updateUpstreamEvent.subscribeOnce(callback, cancellationToken).cancel;
public listenUpstreamOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void {
this.updateUpstreamEvent.subscribeOnce(callback, cancellationToken);
}

@@ -297,4 +293,4 @@

*/
public listenDownstream(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void> {
return this.updateDownstreamEvent.subscribe(callback, cancellationToken).cancel;
public listenDownstream(callback: Callback<T>, cancellationToken?: CancellationToken): void {
this.updateDownstreamEvent.subscribe(callback, cancellationToken);
}

@@ -516,4 +512,4 @@

public listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): Callback<void> {
return this.updateDownstreamEvent.subscribeOnce(callback, cancellationToken).cancel;
public listenOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void {
this.updateDownstreamEvent.subscribeOnce(callback, cancellationToken);
}

@@ -520,0 +516,0 @@

@@ -21,7 +21,7 @@ import { AurumServerInfo, syncObjectDataSource } from '../aurum_server/aurum_server_client.js';

pickDuplex<K extends keyof T>(key: K, cancellationToken?: CancellationToken): DuplexDataSource<T[K]>;
listen(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listenAndRepeat(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listen(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
listenAndRepeat(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
map<D>(mapper: (key: keyof T) => D): ArrayDataSource<D>;
listenOnKey<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, K>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKeyAndRepeat<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void>;
listenOnKey<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, K>>, cancellationToken?: CancellationToken): void;
listenOnKeyAndRepeat<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void;
keys(): string[];

@@ -195,4 +195,4 @@ values(): any;

*/
public listen(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void> {
return this.updateEvent.subscribe(callback, cancellationToken).cancel;
public listen(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void {
this.updateEvent.subscribe(callback, cancellationToken);
}

@@ -225,4 +225,4 @@

*/
public listenAndRepeat(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): Callback<void> {
const c = this.updateEvent.subscribe(callback, cancellationToken).cancel;
public listenAndRepeat(callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void {
this.updateEvent.subscribe(callback, cancellationToken);
for (const key in this.data) {

@@ -236,3 +236,2 @@ callback({

}
return c;
}

@@ -243,7 +242,3 @@

*/
public listenOnKeyAndRepeat<K extends keyof T>(
key: K,
callback: Callback<ObjectChange<T, keyof T>>,
cancellationToken?: CancellationToken
): Callback<void> {
public listenOnKeyAndRepeat<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, keyof T>>, cancellationToken?: CancellationToken): void {
callback({

@@ -255,3 +250,3 @@ key,

return this.listenOnKey(key, callback, cancellationToken);
this.listenOnKey(key, callback, cancellationToken);
}

@@ -262,3 +257,3 @@

*/
public listenOnKey<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, K>>, cancellationToken?: CancellationToken): Callback<void> {
public listenOnKey<K extends keyof T>(key: K, callback: Callback<ObjectChange<T, K>>, cancellationToken?: CancellationToken): void {
if (!this.updateEventOnKey.has(key)) {

@@ -268,3 +263,3 @@ this.updateEventOnKey.set(key, new EventEmitter());

const event = this.updateEventOnKey.get(key);
return event.subscribe(callback as any, cancellationToken).cancel;
event.subscribe(callback as any, cancellationToken);
}

@@ -271,0 +266,0 @@

@@ -284,12 +284,12 @@ import { DataSourceOperator } from './operator_model.js';

public listen(callback: Callback<O>, cancellationToken?: CancellationToken): Callback<void> {
return this.output.listen(callback, cancellationToken);
public listen(callback: Callback<O>, cancellationToken?: CancellationToken): void {
this.output.listen(callback, cancellationToken);
}
public listenAndRepeat(callback: Callback<O>, cancellationToken?: CancellationToken): Callback<void> {
return this.output.listenAndRepeat(callback, cancellationToken);
public listenAndRepeat(callback: Callback<O>, cancellationToken?: CancellationToken): void {
this.output.listenAndRepeat(callback, cancellationToken);
}
public listenOnce(callback: Callback<O>, cancellationToken?: CancellationToken): Callback<void> {
return this.output.listenOnce(callback, cancellationToken);
public listenOnce(callback: Callback<O>, cancellationToken?: CancellationToken): void {
this.output.listenOnce(callback, cancellationToken);
}

@@ -296,0 +296,0 @@

@@ -124,9 +124,9 @@ import { CancellationToken } from '../utilities/cancellation_token.js';

public listen(callback: Callback<TreeChange<T>>, cancellationToken: CancellationToken): Callback<void> {
public listen(callback: Callback<TreeChange<T>>, cancellationToken: CancellationToken): void {
this.watch(cancellationToken);
return this.updateEvent.subscribe(callback, cancellationToken).cancel;
return this.updateEvent.subscribe(callback, cancellationToken);
}
public listenAndRepeat(callback: Callback<TreeChange<T>>, cancellationToken: CancellationToken): Callback<void> {
public listenAndRepeat(callback: Callback<TreeChange<T>>, cancellationToken: CancellationToken): void {
for (const { parent, node, index } of this.iterateLevelWithMetaData(this.roots as any, 0)) {

@@ -141,3 +141,3 @@ callback({

return this.listen(callback, cancellationToken);
this.listen(callback, cancellationToken);
}

@@ -144,0 +144,0 @@

@@ -25,2 +25,16 @@ import { Delegate, Callback } from './common.js';

public static fromPromise<T>(promise: Promise<T>): CancellationToken {
const token = new CancellationToken();
promise.then(() => {
token.cancel();
});
return token;
}
public static fromTimeout(time: number): CancellationToken {
const token = new CancellationToken();
token.setTimeout(() => token.cancel(), time);
return token;
}
public hasCancellables(): boolean {

@@ -187,3 +201,5 @@ return this.cancelables.length > 0;

this._isCancelled = true;
this.cancelables.forEach((c) => c());
for (const c of this.cancelables) {
c();
}
this.cancelables = undefined;

@@ -190,0 +206,0 @@ }

@@ -7,15 +7,4 @@ import { CancellationToken } from '../utilities/cancellation_token.js';

*/
export interface EventSubscriptionFacade {
cancel(): void;
}
/**
* @internal
*/
export type EventCallback<T> = (data: T) => void;
interface EventSubscription<T> {
callback: EventCallback<T>;
}
/**

@@ -25,8 +14,5 @@ * Event emitter is at the core of aurums stream system. It's a basic pub sub style typesafe event system optimized for high update throughput

export class EventEmitter<T> {
private static id: number = 0;
private isFiring: boolean;
private onAfterFire: Array<() => void>;
/**
* Callback that if set is called when all subscriptions are removed
*/
public onEmpty: Callback<void>;

@@ -47,10 +33,11 @@ private static leakWarningThreshold: number;

public get subscriptions(): number {
return this.subscribeChannel.length + this.subscribeOnceChannel.length;
return this.subscribeChannel.size + this.subscribeOnceChannel.length;
}
private subscribeChannel: EventSubscription<T>[];
private subscribeOnceChannel: EventSubscription<T>[];
private subscribeChannel: Map<number, Callback<T>>;
private subscribeOnceChannel: Callback<T>[];
private subscribeCache: Callback<T>[];
constructor() {
this.subscribeChannel = [];
this.subscribeChannel = new Map();
this.subscribeOnceChannel = [];

@@ -150,9 +137,7 @@ this.onAfterFire = [];

*/
public subscribe(callback: EventCallback<T>, cancellationToken?: CancellationToken): EventSubscriptionFacade {
const { facade } = this.createSubscription(callback, this.subscribeChannel, cancellationToken);
if (EventEmitter.leakWarningThreshold && this.subscribeChannel.length > EventEmitter.leakWarningThreshold) {
console.warn(`Observable has ${this.subscribeChannel.length} subscriptions. This could potentially indicate a memory leak`);
public subscribe(callback: EventCallback<T>, cancellationToken?: CancellationToken): void {
this.createSubscription(callback, cancellationToken);
if (EventEmitter.leakWarningThreshold && this.subscribeChannel.size > EventEmitter.leakWarningThreshold) {
console.warn(`Observable has ${this.subscribeChannel.size} subscriptions. This could potentially indicate a memory leak`);
}
return facade;
}

@@ -163,4 +148,4 @@

*/
public subscribeOnce(callback: Callback<T>, cancellationToken?: CancellationToken) {
const { facade } = this.createSubscription(callback, this.subscribeOnceChannel, cancellationToken);
public subscribeOnce(callback: Callback<T>, cancellationToken?: CancellationToken): void {
this.createSubscriptionOnce(callback, cancellationToken);

@@ -170,4 +155,2 @@ if (EventEmitter.leakWarningThreshold && this.subscribeOnceChannel.length > EventEmitter.leakWarningThreshold) {

}
return facade;
}

@@ -187,10 +170,10 @@

if (!this.isFiring) {
this.subscribeChannel.length = 0;
this.subscribeChannel.clear();
this.subscribeCache = undefined;
this.subscribeOnceChannel.length = 0;
this.onEmpty?.();
} else {
this.onAfterFire.push(() => {
this.subscribeChannel.length = 0;
this.subscribeCache = undefined;
this.subscribeChannel.clear();
this.subscribeOnceChannel.length = 0;
this.onEmpty?.();
});

@@ -213,3 +196,3 @@ }

public fire(data?: T): void {
const length = this.subscribeChannel.length;
const length = this.subscribeChannel.size;
const lengthOnce = this.subscribeOnceChannel.length;

@@ -224,5 +207,9 @@ if (length === 0 && lengthOnce === 0) {

if (this.subscribeCache === undefined) {
this.subscribeCache = Array.from(this.subscribeChannel.values());
}
for (let i = 0; i < length; i++) {
try {
this.subscribeChannel[i].callback(data);
this.subscribeCache[i](data);
} catch (e) {

@@ -237,3 +224,3 @@ error = e;

try {
this.subscribeOnceChannel[i].callback(data);
this.subscribeOnceChannel[i](data);
} catch (e) {

@@ -255,44 +242,58 @@ error = e;

private createSubscription(
callback: EventCallback<T>,
channel: EventSubscription<T>[],
cancellationToken?: CancellationToken
): { subscription: EventSubscription<T>; facade: EventSubscriptionFacade } {
const that: this = this;
private createSubscriptionOnce(callback: EventCallback<T>, cancellationToken?: CancellationToken): void {
if (cancellationToken !== undefined) {
cancellationToken.addCancellable(() => this.cancelOnce(callback));
}
if (this.isFiring) {
this.onAfterFire.push(() => this.subscribeOnceChannel.push(callback));
} else {
this.subscribeOnceChannel.push(callback);
}
}
const subscription: EventSubscription<T> = {
callback
};
private createSubscription(callback: EventCallback<T>, cancellationToken?: CancellationToken): void {
const id = EventEmitter.id++;
const facade: EventSubscriptionFacade = {
cancel() {
that.cancel(subscription, channel);
}
};
if (cancellationToken !== undefined) {
cancellationToken.addCancellable(() => that.cancel(subscription, channel));
cancellationToken.addCancellable(() => this.cancel(id));
}
if (this.isFiring) {
this.onAfterFire.push(() => channel.push(subscription));
this.onAfterFire.push(() => {
if (this.subscribeCache === undefined) {
this.subscribeCache = Array.from(this.subscribeChannel.values());
}
this.subscribeCache.push(callback);
this.subscribeChannel.set(id, callback);
});
} else {
channel.push(subscription);
if (this.subscribeCache === undefined) {
this.subscribeCache = Array.from(this.subscribeChannel.values());
}
this.subscribeCache.push(callback);
this.subscribeChannel.set(id, callback);
}
return { subscription, facade };
}
private cancel(subscription: EventSubscription<T>, channel: EventSubscription<T>[]): void {
let index: number = channel.indexOf(subscription);
if (index >= 0) {
if (!this.isFiring) {
channel.splice(index, 1);
if (!this.hasSubscriptions()) {
this.onEmpty?.();
}
private cancelOnce(subscription: Callback<T>): void {
if (!this.isFiring) {
let index: number = this.subscribeOnceChannel.indexOf(subscription);
if (index >= 0) {
this.subscribeOnceChannel.splice(index, 1);
} else {
this.onAfterFire.push(() => this.cancel(subscription, channel));
this.onAfterFire.push(() => this.cancelOnce(subscription));
}
}
}
private cancel(id: number): void {
if (!this.isFiring) {
this.subscribeCache = undefined;
this.subscribeChannel.delete(id);
} else {
this.onAfterFire.push(() => {
this.subscribeCache = undefined;
this.cancel(id);
});
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc