{"version":3,"file":"StateChangeClient.mjs","sources":["../../../../../../core/src/StateChangeClient.ts"],"sourcesContent":["import { UnsubscribeFunction } from './public';\nimport { ISubscriptionService } from './SubscriptionService';\nimport { AllowedOpaqueTokens } from './typeConfig';\n\ntype DeepReadonly<T> = {\n  readonly [P in keyof T]: DeepReadonly<T[P]>;\n};\n\nexport type StateChangeHandler<T> = (state: DeepReadonly<T>) => void;\nexport type StateChangeRegisterFunction<T> = (callback: StateChangeHandler<T>) => UnsubscribeFunction;\n\nexport class StateChangeClient<T> {\n  constructor(\n    private readonly _subscriptionService: ISubscriptionService<T | null, AllowedOpaqueTokens>,\n    private readonly emptyState: T,\n  ) {}\n\n  public onStateChange: StateChangeRegisterFunction<T> = (callback) => {\n    return this._subscriptionService.subscribeToState((state) => {\n      callback(state ?? this.emptyState);\n    });\n  };\n}\n"],"names":["StateChangeClient","emptyState","_subscriptionService","onStateChange","callback","subscribeToState","state"],"mappings":"AAWO,MAAMA,iBAAAA,CAAAA;;;AACX,IAAA,WAAA,CACE,oBAA0F,EACzEC,UAAa,CAC9B;aAFiBC,oBAAAA,GAAAA,oBAAAA;aACAD,UAAAA,GAAAA,UAAAA;AAChB,IAAA;AAEIE,IAAAA,aAAAA,GAAgD,CAACC,QAAAA,GAAAA;AACtD,QAAA,OAAO,IAAI,CAACF,oBAAoB,CAACG,gBAAgB,CAAC,CAACC,KAAAA,GAAAA;YACjDF,QAAAA,CAASE,KAAAA,IAAS,IAAI,CAACL,UAAU,CAAA;AACnC,QAAA,CAAA,CAAA;IACF,CAAA;AACF;;;;"}