JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 120
  • Score
    100M100P100Q74055F
  • License MIT

Add and remove event subscriptions within your template.

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@marko-tags/subscribe) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme


    @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)/>