When to use
Use this when your key is derived from a group + member identity (for example room + user). Each successful create(...) call must be matched with release(id) to prevent memory leaks.
Related: KeyedInstanceFactory docs
API Reference
Base class for grouped keyed instances where ids are generated per group/member combination.
Use this when your key is derived from a group + member identity (for example room + user). Each successful create(...) call must be matched with release(id) to prevent memory leaks.
Related: KeyedInstanceFactory docs
import { GroupedKeyedInstanceFactory } from '@rs-x/core';import { GroupedKeyedInstanceFactory } from '@rs-x/core';
type ChatSubscriptionData = {
roomId: string;
userId: string;
};
class ChatSubscription {
constructor(
public readonly roomId: string,
public readonly userId: string,
) {}
public dispose(): void {
// teardown logic (unsubscribe/close/etc.)
}
}
class ChatSubscriptionFactory extends GroupedKeyedInstanceFactory<
string,
ChatSubscriptionData,
ChatSubscription10 members in this abstract class.
public getId(data: TIdData): TId | undefinedParameters
Returns
TId | undefined
public isGroupRegistered(groupId: unknown): booleanParameters
Returns
boolean
protected createId(data: TData): TIdParameters
Returns
TId
protected abstract createUniqueId(data: TIdData): TIdParameters
Returns
TId
protected getGroup<T>(groupId: unknown): Map<T, TId> | undefinedParameters
Returns
Map<T, TId> | undefined
protected abstract getGroupId(data: TIdData): unknownParameters
Returns
unknown
protected abstract getGroupMemberId(data: TIdData): unknownParameters
Returns
unknown
protected override getOrCreateId(data: TIdData): TIdParameters
Returns
TId
protected override onDispose(): voidParameters
No parameters.
Returns
void
protected override releaseInstance(
_instance: TInstance,
id: TId
): voidParameters
Returns
void