From 69a2aa1ca325ea8fcb55e05d814c5f46580b7e4d Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Wed, 17 Jan 2024 11:13:21 +0100 Subject: [PATCH] Allow calling `get` and `set` without property name --- state.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/state.js b/state.js index 02b6bfb..00c993d 100644 --- a/state.js +++ b/state.js @@ -146,13 +146,22 @@ export class State extends SimpleState { } } - set(prop, value) { + set(...args) { + if (args.length === 1) return this.set("value", ...args) + + const [prop, value] = args this.#target[prop] = value } - get(prop) { + get(...args) { + if (args.length === 0) return this.get("value") + + const prop = args[0] return this.#target[prop] } + + // Backwards compatibility + get proxy() { return this.values } } const forwardFinalizationRegistry = new FinalizationRegistry(([cache, name]) => {