Skip to content

Commit

Permalink
feat(created): v0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sebkolind committed Nov 24, 2023
1 parent 39a57e0 commit 1947e09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 8 additions & 1 deletion example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const Test = {

const List = {
name: 'my-list',
async created () {
this.state.items = await getItems()
},
state: {
items: [
{ id: 1, title: 'List item #1' }
Expand Down Expand Up @@ -87,7 +90,11 @@ one({
<p o-text="msg"></p>
<my-button text="My button"></my-button>
<button id="change-msg">Click me</button>
<my-list></my-list>
<my-list>
<ul>
<li>Loading</li>
</ul>
</my-list>
</div>
`,
setup ({ query, state, props }) {
Expand Down
8 changes: 6 additions & 2 deletions lib/one.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ function one (config) {
? config.parent.el.querySelectorAll(config.name)
: document.querySelectorAll(config.name)

Array.from(els).forEach(el => {
const { setup, ...c } = createInstance({
Array.from(els).forEach(async (el) => {
const { setup, created, ...c } = createInstance({
...config,
state: { ...config.state },
store: Object.freeze({
Expand All @@ -55,6 +55,10 @@ function one (config) {
el
})

if (created) {
await created.bind(c)()
}

template(c)

if (config.components) {
Expand Down

0 comments on commit 1947e09

Please sign in to comment.