0.1.0 • Published 8 years ago

etch-hooks v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

etch-hooks

etch-hooks is a library to facilitate hooking into the Etch component lifecycle.

Overview

It can be useful to hook into the Etch component lifecycle. etch-hooks allows you to hook into either (or both) of the etch.initialize and etch.update methods:

import hooks from 'etch-hooks'

class MyComponent {
  constructor () {
    hooks.onInitialize(this, this.onUpdate)
    hooks.onUpdate(this, this.onUpdate)

    etch.initialize(this)
    // the `onInitialize` hook runs here
  }

  async update (props, children) {
    // ...
    await etch.update(this)
    // the `onUpdate` hook runs here;
    // remember that `etch.update` is asynchronous and returns a promise
  }

  onUpdate () {
    console.log("I've been rendered!")
  }

  render () {
    // ...
  }
}