Skip to content

Commit

Permalink
have el in first arg instead
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind committed Nov 15, 2023
1 parent 4970ba2 commit 7441936
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
6 changes: 2 additions & 4 deletions example/app.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
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,
text: 'Click me'
})
})

const Button = new O(function () {
this.el = 'button'
const Button = new O('button', function () {
this.setScope(Component)

this.on('click', function (data) {
Expand Down
8 changes: 3 additions & 5 deletions lib/one.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -17,10 +19,6 @@ class O {
}
}

set el (el) {
this.#el = typeof el === 'string' ? document.querySelectorAll(el) : el
}

get el () {
return this.#el
}
Expand Down

0 comments on commit 7441936

Please sign in to comment.