refactor(frontend): boot分割したり副作用減らしたりとか

#10838
This commit is contained in:
syuilo
2023-05-15 19:08:46 +09:00
parent a7ee4aabcb
commit 23f106a0c1
26 changed files with 628 additions and 573 deletions

View File

@@ -6,7 +6,7 @@ import { $i } from './account';
import { api } from './os';
import { get, set } from './scripts/idb-proxy';
import { defaultStore } from './store';
import { stream } from './stream';
import { useStream } from './stream';
import { deepClone } from './scripts/clone';
type StateDef = Record<string, {
@@ -26,8 +26,6 @@ type PizzaxChannelMessage<T extends StateDef> = {
userId?: string;
};
const connection = $i && stream.useChannel('main');
export class Storage<T extends StateDef> {
public readonly ready: Promise<void>;
public readonly loaded: Promise<void>;
@@ -105,8 +103,10 @@ export class Storage<T extends StateDef> {
});
if ($i) {
const connection = useStream().useChannel('main');
// streamingのuser storage updateイベントを監視して更新
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 || scope.length !== 2 || scope[0] !== 'client' || scope[1] !== this.key || this.state[key] === value) return;
this.reactiveState[key].value = this.state[key] = value;