From 7441936f2af8f7189abdc03349769d75d5148df6 Mon Sep 17 00:00:00 2001 From: "Sebastian L. K. Sorensen" Date: Thu, 16 Nov 2023 00:14:32 +0100 Subject: [PATCH] have `el` in first arg instead --- example/app.js | 6 ++---- lib/one.js | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/example/app.js b/example/app.js index c75b0871..35ee95e2 100644 --- a/example/app.js +++ b/example/app.js @@ -1,7 +1,6 @@ import { O } from '../dist/one' -const Component = new O(function () { - this.el = '[hello-world]' +const Component = new O('[hello-world]', function () { this.setState({ name: 'John Doe', count: 0, @@ -9,8 +8,7 @@ const Component = new O(function () { }) }) -const Button = new O(function () { - this.el = 'button' +const Button = new O('button', function () { this.setScope(Component) this.on('click', function (data) { diff --git a/lib/one.js b/lib/one.js index 19b33f66..f5ea47d5 100644 --- a/lib/one.js +++ b/lib/one.js @@ -5,7 +5,9 @@ class O { #scope = null #state = {} - constructor (setup) { + constructor (el, setup) { + this.#el = typeof el === 'string' ? document.querySelectorAll(el) : el + setup.bind(this)() if (!this.#el) { @@ -17,10 +19,6 @@ class O { } } - set el (el) { - this.#el = typeof el === 'string' ? document.querySelectorAll(el) : el - } - get el () { return this.#el }