@marko-tags/subscribe

0.5.1 • Public • Published


@marko-tags/subscribe
API Stability NPM Version Downloads

Add and remove event subscriptions within your template.

Installation

npm install @marko-tags/subscribe

Example

class {
    onCreate() {
        this.state = {
            listening: false
        }
    }

    toggle() {
        this.state.listening = !this.state.listening;
    }

    handleMove(e) {
      ...
    }
}

<button on-click('toggle')>
  <if(state.listening)>
    <!-- Only logs mouse moves if we are in the listening state -->
    <subscribe to=window on-mousemove('handleMove')/>
    Stop Listening
  </if>
  <else>
    Listen
  </else>
</button>

API

<subscribe
  to=EventEmitter|EventTarget
  on-*(string, ...args)
  once-*(string, ...args)/>

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @marko-tags/subscribe

      Weekly Downloads

      48

      Version

      0.5.1

      License

      MIT

      Unpacked Size

      9.6 kB

      Total Files

      8

      Last publish

      Collaborators

      • dylanpiercey
      • mlrawlings
      • agliga