@lo-fi/common
Advanced tools
Comparing version 1.10.4 to 1.11.0
export declare class EventSubscriber<Events extends { | ||
[key: string]: (...args: any[]) => void; | ||
}> { | ||
private _onAllUnsubscribed?; | ||
protected subscribers: Record<string, Record<string, (...args: any[]) => void>>; | ||
protected counts: Record<string, number>; | ||
private _disabled; | ||
constructor(_onAllUnsubscribed?: ((event: keyof Events) => void) | undefined); | ||
get disabled(): boolean; | ||
@@ -8,0 +10,0 @@ subscriberCount: (event: Extract<keyof Events, string>) => number; |
@@ -6,3 +6,4 @@ "use strict"; | ||
class EventSubscriber { | ||
constructor() { | ||
constructor(_onAllUnsubscribed) { | ||
this._onAllUnsubscribed = _onAllUnsubscribed; | ||
this.subscribers = {}; | ||
@@ -27,4 +28,14 @@ this.counts = {}; | ||
return () => { | ||
// already removed | ||
if (!this.subscribers[event]) | ||
return; | ||
delete this.subscribers[event][key]; | ||
this.counts[event]--; | ||
if (this.counts[event] === 0) { | ||
delete this.subscribers[event]; | ||
delete this.counts[event]; | ||
if (this._onAllUnsubscribed) { | ||
this._onAllUnsubscribed(event); | ||
} | ||
} | ||
}; | ||
@@ -40,4 +51,10 @@ }; | ||
this.dispose = () => { | ||
const events = Object.keys(this.subscribers); | ||
this.subscribers = {}; | ||
this.counts = {}; | ||
events.forEach((event) => { | ||
if (this._onAllUnsubscribed) { | ||
this._onAllUnsubscribed(event); | ||
} | ||
}); | ||
}; | ||
@@ -44,0 +61,0 @@ this.disable = () => { |
@@ -45,3 +45,3 @@ import { ObjectRef } from './operation.js'; | ||
export declare function ensureOid(obj: any, rootOid: ObjectIdentifier, key: string | number, createSubId?: () => string): string; | ||
export declare function createOid(collection: string, documentId: string, keyPath: KeyPath, subId?: string): string; | ||
export declare function createOid(collection: string, documentId: string, keyPath?: KeyPath, subId?: string): string; | ||
export declare function createSubOid(root: ObjectIdentifier, key: string | number, createSubId?: () => string): string; | ||
@@ -48,0 +48,0 @@ export declare function decomposeOid(oid: ObjectIdentifier): { |
@@ -86,3 +86,3 @@ "use strict"; | ||
} | ||
function createOid(collection, documentId, keyPath, subId) { | ||
function createOid(collection, documentId, keyPath = [], subId) { | ||
let oid = sanitizeFragment(collection) + | ||
@@ -89,0 +89,0 @@ COLLECTION_SEPARATOR + |
export declare class EventSubscriber<Events extends { | ||
[key: string]: (...args: any[]) => void; | ||
}> { | ||
private _onAllUnsubscribed?; | ||
protected subscribers: Record<string, Record<string, (...args: any[]) => void>>; | ||
protected counts: Record<string, number>; | ||
private _disabled; | ||
constructor(_onAllUnsubscribed?: ((event: keyof Events) => void) | undefined); | ||
get disabled(): boolean; | ||
@@ -8,0 +10,0 @@ subscriberCount: (event: Extract<keyof Events, string>) => number; |
import { generateId } from './utils.js'; | ||
export class EventSubscriber { | ||
constructor() { | ||
constructor(_onAllUnsubscribed) { | ||
this._onAllUnsubscribed = _onAllUnsubscribed; | ||
this.subscribers = {}; | ||
@@ -23,4 +24,14 @@ this.counts = {}; | ||
return () => { | ||
// already removed | ||
if (!this.subscribers[event]) | ||
return; | ||
delete this.subscribers[event][key]; | ||
this.counts[event]--; | ||
if (this.counts[event] === 0) { | ||
delete this.subscribers[event]; | ||
delete this.counts[event]; | ||
if (this._onAllUnsubscribed) { | ||
this._onAllUnsubscribed(event); | ||
} | ||
} | ||
}; | ||
@@ -36,4 +47,10 @@ }; | ||
this.dispose = () => { | ||
const events = Object.keys(this.subscribers); | ||
this.subscribers = {}; | ||
this.counts = {}; | ||
events.forEach((event) => { | ||
if (this._onAllUnsubscribed) { | ||
this._onAllUnsubscribed(event); | ||
} | ||
}); | ||
}; | ||
@@ -40,0 +57,0 @@ this.disable = () => { |
@@ -45,3 +45,3 @@ import { ObjectRef } from './operation.js'; | ||
export declare function ensureOid(obj: any, rootOid: ObjectIdentifier, key: string | number, createSubId?: () => string): string; | ||
export declare function createOid(collection: string, documentId: string, keyPath: KeyPath, subId?: string): string; | ||
export declare function createOid(collection: string, documentId: string, keyPath?: KeyPath, subId?: string): string; | ||
export declare function createSubOid(root: ObjectIdentifier, key: string | number, createSubId?: () => string): string; | ||
@@ -48,0 +48,0 @@ export declare function decomposeOid(oid: ObjectIdentifier): { |
@@ -76,3 +76,3 @@ import { v4 } from 'uuid'; | ||
} | ||
export function createOid(collection, documentId, keyPath, subId) { | ||
export function createOid(collection, documentId, keyPath = [], subId) { | ||
let oid = sanitizeFragment(collection) + | ||
@@ -79,0 +79,0 @@ COLLECTION_SEPARATOR + |
{ | ||
"name": "@lo-fi/common", | ||
"version": "1.10.4", | ||
"version": "1.11.0", | ||
"access": "public", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -13,2 +13,4 @@ import { generateId } from './utils.js'; | ||
constructor(private _onAllUnsubscribed?: (event: keyof Events) => void) {} | ||
get disabled() { | ||
@@ -38,4 +40,14 @@ return this._disabled; | ||
return () => { | ||
// already removed | ||
if (!this.subscribers[event]) return; | ||
delete this.subscribers[event][key]; | ||
this.counts[event]--; | ||
if (this.counts[event] === 0) { | ||
delete this.subscribers[event]; | ||
delete this.counts[event]; | ||
if (this._onAllUnsubscribed) { | ||
this._onAllUnsubscribed(event); | ||
} | ||
} | ||
}; | ||
@@ -55,4 +67,10 @@ }; | ||
dispose = () => { | ||
const events = Object.keys(this.subscribers); | ||
this.subscribers = {} as any; | ||
this.counts = {} as any; | ||
events.forEach((event) => { | ||
if (this._onAllUnsubscribed) { | ||
this._onAllUnsubscribed(event); | ||
} | ||
}); | ||
}; | ||
@@ -59,0 +77,0 @@ |
@@ -132,3 +132,3 @@ import { v4 } from 'uuid'; | ||
documentId: string, | ||
keyPath: KeyPath, | ||
keyPath: KeyPath = [], | ||
subId?: string, | ||
@@ -135,0 +135,0 @@ ) { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
765090
14367