some fixes

This commit is contained in:
syuilo
2020-12-28 17:00:31 +09:00
parent 20c076b369
commit 948a65bf39
8 changed files with 92 additions and 70 deletions

View File

@@ -1,4 +1,4 @@
import { Ref, ref, watch } from 'vue';
import { onUnmounted, Ref, ref, watch } from 'vue';
import { $i } from './account';
import { api } from './os';
@@ -104,8 +104,16 @@ export class Storage<T extends StateDef> {
* 主にvue場で設定コントロールのmodelとして使う用
*/
public makeGetterSetter<K extends keyof T>(key: K, getter?: (v: T[K]) => unknown, setter?: (v: unknown) => T[K]) {
// TODO: VueのcustomRef使うと良い感じになるかも
const valueRef = ref(this.state[key]);
const stop = watch(this.reactiveState[key], val => {
valueRef.value = val;
});
onUnmounted(() => {
stop();
});
// TODO: VueのcustomRef使うと良い感じになるかも
return {
get: () => {
if (getter) {