From 3f21c17b2894bdfb643334d6ed331fc6bdb1d49c Mon Sep 17 00:00:00 2001 From: tamaina Date: Thu, 30 Dec 2021 02:38:17 +0900 Subject: [PATCH] fix pizzax (#8099) --- packages/client/src/pizzax.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/client/src/pizzax.ts b/packages/client/src/pizzax.ts index 0611599a2..fc01e92ee 100644 --- a/packages/client/src/pizzax.ts +++ b/packages/client/src/pizzax.ts @@ -10,6 +10,8 @@ type StateDef = Record = A extends readonly (infer T)[] ? T : never; +const connection = $i && stream.useChannel('main'); + export class Storage { public readonly key: string; public readonly keyForLocalStorage: string; @@ -20,8 +22,6 @@ export class Storage { public readonly state: { [K in keyof T]: T[K]['default'] }; public readonly reactiveState: { [K in keyof T]: Ref }; - private connection = stream.useChannel('main'); - constructor(key: string, def: T) { this.key = key; this.keyForLocalStorage = 'pizzax::' + key; @@ -73,7 +73,7 @@ export class Storage { }); }, 1); // streamingのuser storage updateイベントを監視して更新 - this.connection.on('registryUpdated', ({ scope, key, value }: { scope: string[], key: keyof T, value: T[typeof key]['default'] }) => { + connection?.on('registryUpdated', ({ scope, key, value }: { scope: string[], key: keyof T, value: T[typeof key]['default'] }) => { if (scope[1] !== this.key || this.state[key] === value) return; this.state[key] = value;