Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat: event-based lifecycle hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
aidenybai committed Apr 25, 2021
1 parent 485c166 commit 29cc06c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export class Component {

setElementCustomProp(rootEl, COMPONENT_FLAG, this);

const mountedEvent = new CustomEvent('mount');
rootEl.dispatchEvent(mountedEvent);

return this.state;
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const render = (
}
}
}

// Effect is like a watcher but detects changes to an el
if (node.directives['on:effect']) {
const effectEvent = new CustomEvent('effect');
node.el.dispatchEvent(effectEvent);
}
}
})();
};
Expand Down

0 comments on commit 29cc06c

Please sign in to comment.