diff --git a/package.json b/package.json index e57ba03..0427f39 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "skooma", - "version": "1.6.1", + "version": "1.7.0", "author": "darkwiiplayer", "license": "Unlicense", "main": "skooma.js", diff --git a/state.js b/state.js index 00c993d..b4306e1 100644 --- a/state.js +++ b/state.js @@ -160,6 +160,17 @@ export class State extends SimpleState { return this.#target[prop] } + subscribe(prop, callback) { + if (!callback) return this.subscribe("value", prop) + + const controller = new AbortController() + this.addEventListener("change", ({final}) => { + if (final.has(prop)) return callback(final.get(prop)) + }, {signal: controller.signal}) + callback(this.value) + return () => controller.abort() + } + // Backwards compatibility get proxy() { return this.values } }