Skip to content

Latest commit

 

History

History
20 lines (18 loc) · 596 Bytes

05_Singleton.md

File metadata and controls

20 lines (18 loc) · 596 Bytes

Singleton

The Singleton is a Plugin that will never be destroyed or re-initialized after it has been loaded. This example plugin will only be bound to your page once, and will never be destroyed if you change the page.

import Magna, { Singleton } from '@coredna/magna'
import $ from 'jquery'

class MySingleton extends Singleton {
  init({ request }) {
    this.$elem = $(this.config.selector).on('click', this._handleClick)
  }
  _handleClick = e => {
    console.log('clicked element', e)
  }
}
new Magna([
  new MySingleton({ selector: '#my-element' }),
]).start()