wip
This commit is contained in:
		
							parent
							
								
									d53795184c
								
							
						
					
					
						commit
						d77fa3bb08
					
				
					 1 changed files with 11 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
import { onUnmounted, Ref, ref, watch } from 'vue';
 | 
			
		||||
import { $i } from './account';
 | 
			
		||||
import { api } from './os';
 | 
			
		||||
import { api, stream } from './os';
 | 
			
		||||
 | 
			
		||||
type StateDef = Record<string, {
 | 
			
		||||
	where: 'account' | 'device' | 'deviceAccount';
 | 
			
		||||
| 
						 | 
				
			
			@ -19,6 +19,8 @@ export class Storage<T extends StateDef> {
 | 
			
		|||
	public readonly state: { [K in keyof T]: T[K]['default'] };
 | 
			
		||||
	public readonly reactiveState: { [K in keyof T]: Ref<T[K]['default']> };
 | 
			
		||||
 | 
			
		||||
	private connection = stream.useChannel('main');
 | 
			
		||||
 | 
			
		||||
	constructor(key: string, def: T) {
 | 
			
		||||
		this.key = key;
 | 
			
		||||
		this.keyForLocalStorage = 'pizzax::' + key;
 | 
			
		||||
| 
						 | 
				
			
			@ -70,7 +72,14 @@ export class Storage<T extends StateDef> {
 | 
			
		|||
				});
 | 
			
		||||
			}, 1);
 | 
			
		||||
 | 
			
		||||
			// TODO: streamingのuser storage updateイベントを監視して更新
 | 
			
		||||
			// streamingのuser storage updateイベントを監視して更新
 | 
			
		||||
			this.connection.on('registryUpdated', ({ scope, key, value }) => {
 | 
			
		||||
				this.state[key] = value;
 | 
			
		||||
				this.reactiveState[key].value = value;
 | 
			
		||||
				const cache = JSON.parse(localStorage.getItem(this.keyForLocalStorage + '::cache::' + $i.id) || '{}');
 | 
			
		||||
				cache[key] = value;
 | 
			
		||||
				localStorage.setItem(this.keyForLocalStorage + '::cache::' + $i.id, JSON.stringify(cache));
 | 
			
		||||
			});
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue