From e5251d23f158c7cc092121c3a7cc0438a73746ec Mon Sep 17 00:00:00 2001 From: Aylur Date: Mon, 15 Jul 2024 22:09:58 +0200 Subject: remove python and node I have no desire to work on the python version The node version has the issue of promises not working which makes it unusable but gjs works just as good if not better. Might look back into node later --- node/src/binding.ts | 78 ----------------------------------------------------- 1 file changed, 78 deletions(-) delete mode 100644 node/src/binding.ts (limited to 'node/src/binding.ts') diff --git a/node/src/binding.ts b/node/src/binding.ts deleted file mode 100644 index a8b6d55..0000000 --- a/node/src/binding.ts +++ /dev/null @@ -1,78 +0,0 @@ -export const kebabify = (str: string) => str - .replace(/([a-z])([A-Z])/g, "$1-$2") - .replaceAll("_", "-") - .toLowerCase() - -export interface Subscribable { - subscribe(callback: () => void): () => void - get(): T - [key: string]: any -} - -export interface Connectable { - connect(signal: string, callback: (...args: any[]) => unknown): number - disconnect(id: number): void - [key: string]: any -} - -export default class Binding { - private emitter: Subscribable | Connectable - private prop?: string - private transformFn = (v: any) => v - - static bind< - T extends Connectable, - P extends keyof T, - >(object: T, property: P): Binding - - static bind(object: Subscribable): Binding - - static bind(emitter: Connectable | Subscribable, prop?: string) { - return new Binding(emitter, prop) - } - - private constructor(emitter: Connectable | Subscribable, prop?: string) { - this.emitter = emitter - this.prop = prop && kebabify(prop) - } - - toString() { - return `Binding<${this.emitter}${this.prop ? `, "${this.prop}"` : ""}>` - } - - as(fn: (v: Value) => T): Binding { - const bind = new Binding(this.emitter, this.prop) - bind.transformFn = (v: Value) => fn(this.transformFn(v)) - return bind as unknown as Binding - } - - get(): Value { - if (typeof this.emitter.get === "function") - return this.transformFn(this.emitter.get()) - - if (typeof this.prop === "string") - return this.transformFn(this.emitter[this.prop]) - - throw Error("can not get value of binding") - } - - subscribe(callback: (value: Value) => void): () => void { - if (typeof this.emitter.subscribe === "function") { - return this.emitter.subscribe(() => { - callback(this.get()) - }) - } - else if (typeof this.emitter.connect === "function") { - const signal = `notify::${this.prop}` - const id = this.emitter.connect(signal, () => { - callback(this.get()) - }) - return () => { - (this.emitter.disconnect as Connectable["disconnect"])(id) - } - } - throw Error(`${this.emitter} is not bindable`) - } -} - -export const { bind } = Binding -- cgit v1.2.3