Skip to content

Class: ReactiveModelIntrospector<T, PK, R> ​

A testing utility class for introspecting and testing ReactiveModel instances. This class is designed to help with testing by exposing internal state that would otherwise be inaccessible due to TypeScript's private field declarations.

Type Parameters ​

Type ParameterDescription
T extends PlainObjectThe shape of the model's data as a plain object
PK extends StringKeyOf<T>The primary key field of the model, must be a string key of T
R extends Record<string, RelationshipConfiguration>Record of relationship configurations for the model

Constructors ​

Constructor ​

ts
new ReactiveModelIntrospector<T, PK, R>(): ReactiveModelIntrospector<T, PK, R>;

Returns ​

ReactiveModelIntrospector<T, PK, R>

Accessors ​

boundOnReactiveModelDeletedInSwarm ​

Get Signature ​

ts
get boundOnReactiveModelDeletedInSwarm(): undefined | (modelName: string, instanceKey: string) => void;

Gets the bound handler for model deletions in Swarm

Throws ​

If accessed before initialization

Returns ​

undefined | (modelName: string, instanceKey: string) => void


boundOnReactiveModelUpdatedInSwarm ​

Get Signature ​

ts
get boundOnReactiveModelUpdatedInSwarm():
  | undefined
  | (modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void;

Gets the bound handler for model updates in Swarm

Throws ​

If accessed before initialization

Returns ​

| undefined | (modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void


deleted ​

Get Signature ​

ts
get deleted(): boolean;

Gets the deleted status of the model

Throws ​

If accessed before initialization

Returns ​

boolean


emitter ​

Get Signature ​

ts
get emitter(): ReactiveModelChangeEmitter<T, PK, R>;

Gets the ReactiveModelChangeEmitter instance

Throws ​

If accessed before initialization

Returns ​

ReactiveModelChangeEmitter<T, PK, R>


encryption ​

Get Signature ​

ts
get encryption(): Encryption;

Gets the Encryption instance used for data encryption

Throws ​

If accessed before initialization

Returns ​

Encryption


logBus ​

Get Signature ​

ts
get logBus(): TypedEventEmitter<LogBusEventMap>;

Gets the LogBus event emitter instance

Throws ​

If accessed before initialization

Returns ​

TypedEventEmitter<LogBusEventMap>


modelKey ​

Get Signature ​

ts
get modelKey(): string;

Gets the model's unique key

Throws ​

If accessed before initialization

Returns ​

string


modelName ​

Get Signature ​

ts
get modelName(): string;

Gets the model's name

Throws ​

If accessed before initialization

Returns ​

string


pending ​

Get Signature ​

ts
get pending(): Map<StringKeyOf<T>, T[StringKeyOf<T>]>;

Gets the map of pending changes

Throws ​

If accessed before initialization

Returns ​

Map<StringKeyOf<T>, T[StringKeyOf<T>]>


primaryKey ​

Get Signature ​

ts
get primaryKey(): PK;

Gets the primary key field name

Throws ​

If accessed before initialization

Returns ​

PK


properties ​

Get Signature ​

ts
get properties(): readonly StringKeyOf<T>[];

Gets the array of model property names

Throws ​

If accessed before initialization

Returns ​

readonly StringKeyOf<T>[]


relationships ​

Get Signature ​

ts
get relationships(): Record<string, Relationship>;

Gets the model's relationships

Throws ​

If accessed before initialization

Returns ​

Record<string, Relationship>


state ​

Get Signature ​

ts
get state(): Map<StringKeyOf<T>, T[StringKeyOf<T>]>;

Gets the current state map

Throws ​

If accessed before initialization

Returns ​

Map<StringKeyOf<T>, T[StringKeyOf<T>]>


swarm ​

Get Signature ​

ts
get swarm(): UnifiedEventBus;

Gets the Swarm instance used for reactive state synchronization

Throws ​

If accessed before initialization

Returns ​

UnifiedEventBus


table ​

Get Signature ​

ts
get table(): EntityTable<T>;

Gets the Dexie EntityTable instance

Throws ​

If accessed before initialization

Returns ​

EntityTable<T>


throwError ​

Get Signature ​

ts
get throwError(): (err: Error) => void;

Gets the error throwing function

Throws ​

If accessed before initialization

Returns ​
ts
(err: Error): void;
Parameters ​
ParameterType
errError
Returns ​

void

Methods ​

$init() ​

ts
$init(
   swarm: () => UnifiedEventBus,
   encryption: () => Encryption,
   logBus: () => TypedEventEmitter<LogBusEventMap>,
   throwError: () => (err: Error) => void,
   table: () => EntityTable<T>,
   properties: () => readonly StringKeyOf<T>[],
   primaryKey: () => PK,
   modelName: () => string,
   modelKey: () => string,
   pending: () => Map<StringKeyOf<T>, T[StringKeyOf<T>]>,
   state: () => Map<StringKeyOf<T>, T[StringKeyOf<T>]>,
   emitter: () => ReactiveModelChangeEmitter<T, PK, R>,
   relationships: () => Record<string, Relationship>,
   deleted: () => boolean,
   boundOnReactiveModelUpdatedInSwarm: () =>
  | undefined
  | (modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void,
   boundOnReactiveModelDeletedInSwarm: () => undefined | (modelName: string, instanceKey: string) => void,
   onReactiveModelUpdatedInSwarm: (modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void,
   onReactiveModelDeletedInSwarm: (modelName: string, instanceKey: string) => void,
   getProperty: <P>(prop: P) => undefined | T[P],
   getRelatedProperty: <P>(prop: P) => any,
   setProperty: <P>(prop: P, value: T[P]) => void,
   doEmitChanges: () => void): void;

Initializes the introspector with all necessary dependencies and functions. This method can only be called once. Subsequent calls will throw an error.

Parameters ​

ParameterType
swarm() => UnifiedEventBus
encryption() => Encryption
logBus() => TypedEventEmitter<LogBusEventMap>
throwError() => (err: Error) => void
table() => EntityTable<T>
properties() => readonly StringKeyOf<T>[]
primaryKey() => PK
modelName() => string
modelKey() => string
pending() => Map<StringKeyOf<T>, T[StringKeyOf<T>]>
state() => Map<StringKeyOf<T>, T[StringKeyOf<T>]>
emitter() => ReactiveModelChangeEmitter<T, PK, R>
relationships() => Record<string, Relationship>
deleted() => boolean
boundOnReactiveModelUpdatedInSwarm() => | undefined | (modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void
boundOnReactiveModelDeletedInSwarm() => undefined | (modelName: string, instanceKey: string) => void
onReactiveModelUpdatedInSwarm(modelName: string, instanceKey: string, values: Record<StringKeyOf<T>, string>) => void
onReactiveModelDeletedInSwarm(modelName: string, instanceKey: string) => void
getProperty<P>(prop: P) => undefined | T[P]
getRelatedProperty<P>(prop: P) => any
setProperty<P>(prop: P, value: T[P]) => void
doEmitChanges() => void

Returns ​

void

Throws ​

If attempting to reinitialize any property


doEmitChanges() ​

ts
doEmitChanges(): void;

Emits any pending changes to subscribers

Returns ​

void

Throws ​

If accessed before initialization


getProperty() ​

ts
getProperty<P>(prop: P): undefined | T[P];

Gets a property value from the model

Type Parameters ​

Type Parameter
P extends string

Parameters ​

ParameterTypeDescription
propPName of the property to get

Returns ​

undefined | T[P]

The property value or undefined if not found

Throws ​

If accessed before initialization


getRelatedProperty() ​

ts
getRelatedProperty<P>(prop: P): any;

Gets a related property value from the model's relationships

Type Parameters ​

Type Parameter
P extends string

Parameters ​

ParameterTypeDescription
propPName of the related property to get

Returns ​

any

The related property value or undefined if not found

Throws ​

If accessed before initialization


onReactiveModelDeletedInSwarm() ​

ts
onReactiveModelDeletedInSwarm(modelName: string, instanceKey: string): void;

Handles model deletion events in Swarm

Parameters ​

ParameterTypeDescription
modelNamestringName of the model being deleted
instanceKeystringUnique key of the model instance

Returns ​

void

Throws ​

If accessed before initialization


setProperty() ​

ts
setProperty<P>(prop: P, value: T[P]): void;

Sets a property value on the model

Type Parameters ​

Type Parameter
P extends string

Parameters ​

ParameterTypeDescription
propPName of the property to set
valueT[P]Value to set for the property

Returns ​

void

Throws ​

If accessed before initialization