From 8da6a2174296bc1b78c6dde13f6bca46e67e156a Mon Sep 17 00:00:00 2001 From: Aylur Date: Sun, 1 Sep 2024 20:19:39 +0000 Subject: docs: variable --- core/gjs/src/variable.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'core/gjs/src') diff --git a/core/gjs/src/variable.ts b/core/gjs/src/variable.ts index d583ab1..9528ffe 100644 --- a/core/gjs/src/variable.ts +++ b/core/gjs/src/variable.ts @@ -166,12 +166,14 @@ class VariableWrapper extends Function { observe( objs: Array<[obj: Connectable, signal: string]>, - callback: (...args: any[]) => T): Variable + callback: (...args: any[]) => T, + ): Variable observe( obj: Connectable, signal: string, - callback: (...args: any[]) => T): Variable + callback: (...args: any[]) => T, + ): Variable observe( objs: Connectable | Array<[obj: Connectable, signal: string]>, @@ -184,12 +186,15 @@ class VariableWrapper extends Function { if (Array.isArray(objs)) { for (const obj of objs) { const [o, s] = obj - o.connect(s, set) + const id = o.connect(s, set) + this.onDropped(() => o.disconnect(id)) } } else { - if (typeof sigOrFn === "string") - objs.connect(sigOrFn, set) + if (typeof sigOrFn === "string") { + const id = objs.connect(sigOrFn, set) + this.onDropped(() => objs.disconnect(id)) + } } return this as unknown as Variable @@ -199,7 +204,7 @@ class VariableWrapper extends Function { const Deps extends Array | Binding>, Args extends { [K in keyof Deps]: Deps[K] extends Variable - ? T : Deps[K] extends Binding ? T : never + ? T : Deps[K] extends Binding ? T : never }, V = Args, >(deps: Deps, fn: (...args: Args) => V = (...args) => args as unknown as V) { @@ -221,7 +226,7 @@ export const Variable = new Proxy(VariableWrapper as any, { }) as { derive: typeof VariableWrapper["derive"] (init: T): Variable - new(init: T): Variable + new (init: T): Variable } export default Variable -- cgit v1.2.3