Skip to content

Conversation

@joshgillies
Copy link
Owner

Adds onload and onunload lifecycle hooks.

@WebReflection
Copy link

Remember, hyperHTML.wire() witohut a reference does the whole parsing circus every single time.

You are working with components here, and using an explicit render() method.

If I were you, I would drop the render(render, whatever) { return rendertemplate; } and use the following approach instead:

const Button = component({
  onload: (e) => {
    console.log(e, 'loaded')
  },
  onunload: (e) => {
    console.log(e, 'unloaded')
  },
  render: (text) => hyperHTML.wire(this)`
    <button onclick="${(e) => e.target.parentNode.removeChild(e.target)}">
      ${text}
    </button>
  `
})

and I am assuming you are using different instances of the same component each time.

With my example, you'd parse the template and create the magic hyperHTML hooks lazily and only the very first time. Every other time that .render(text) call will be lightening fast 😉

@joshgillies joshgillies mentioned this pull request Apr 20, 2017
Merged
3 tasks
@joshgillies
Copy link
Owner Author

@WebReflection thanks so much for the above feedback! I'm going to merge this PR as it serves as a nice base for what I'm now working on in #2. Please feel free to take a look if you have the time. 👍

@joshgillies joshgillies merged commit aba0d61 into master Apr 20, 2017
@joshgillies joshgillies deleted the lifecycle-events branch April 20, 2017 10:45
@joshgillies joshgillies restored the lifecycle-events branch April 25, 2017 22:38
@joshgillies joshgillies deleted the lifecycle-events branch April 25, 2017 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants