github Tencent/omi v4.0.13
Observe elements are defined in a cleaner way

latest releases: v7.7.0, v7.6.18, v7.6.6...
6 years ago
import { render, WeElement, define } from 'omi'

define('my-counter', class extends WeElement {
    static observe = true
    
    data = {
      count: 1
    }

    sub = () => {
      this.data.count--
    }

    add = () => {
      this.data.count++
    }

    render() {
      return (
        <div>
          <button onClick={this.sub}>-</button>
          <span>{this.data.count}</span>
          <button onClick={this.add}>+</button>
        </div>
      )
    }
  })

render(<my-counter />, 'body')

Don't miss a new omi release

NewReleases is sending notifications on new releases.