From 12daec85e6e2254bf0bf9c6a534df76d9a56d344 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Thu, 29 Feb 2024 15:33:26 +0100 Subject: [PATCH] Extract Ref class into separate module --- ref.js | 18 ++++++++++++++++++ skooma.js | 19 ------------------- 2 files changed, 18 insertions(+), 19 deletions(-) create mode 100644 ref.js diff --git a/ref.js b/ref.js new file mode 100644 index 0000000..1bbfd7d --- /dev/null +++ b/ref.js @@ -0,0 +1,18 @@ +/** A reference to a reactive element that follows it around through changes */ +export class Ref { + #current + /** @param {Element|Text} target A reactive element to follow */ + constructor(target) { + this.#current = target + this.follow(target) + } + + follow(target) { + target.addEventListener("replaced", ({next}) => { + this.#current = next + this.follow(next) + }) + } + + deref() { return this.#current } +} diff --git a/skooma.js b/skooma.js index 5be4037..702d983 100644 --- a/skooma.js +++ b/skooma.js @@ -152,25 +152,6 @@ export const reactiveElement = observable => { return element } -/** A reference to a reactive element that follows it around through changes */ -export class Ref { - #current - /** @param {Element|Text} target A reactive element to follow */ - constructor(target) { - this.#current = target - this.follow(target) - } - - follow(target) { - target.addEventListener("replaced", ({next}) => { - this.#current = next - this.follow(next) - }) - } - - deref() { return this.#current } -} - /** Set an attribute on an element * @param {Element} element * @param {string} attribute