7.0.0 • Published 5 years ago

emmy v7.0.0

Weekly downloads
1,950
License
MIT
Repository
github
Last release
5 years ago

Emmy Build Status

Events toolkit.

  • Multiple events on(el, 'click touchstart', cb)
  • Event classes on(el, 'click.x', cb), off(el, '.x')
  • Uses native events, if available.
  • Delegate on('.subel', 'click', cb, { target: container })

Usage

npm install emmy

import {on, off, emit} from 'emmy'

on(el, 'evt.foo', e => {})
emit(el, 'evt', {x: 1})
off(el, '.foo')

API

off = on(target, event, handler, opts?)

Bind event handler to target events.

  • event can be a string or an array, optionally with class suffixes click.tag1.tag2
  • target can be an element, list, or a string to delegate events.
  • opts can provide opts.target for delegate target and listener props.
// dragging scheme
on(el, 'mousedown touchstart', () => {
	// ...init drag

	on(el, 'mousemove.drag touchmove.drag', () => {
		// ...handle drag
	})

	on(el, 'mouseup.drag touchend.drag', () => {
		off(el, '.drag')
		// ...end drag
	})
})

// delegate
let off = on('.selector', 'click', handler, { element: container })

// remove listener
off()

off(target, event?, callback?)

Remove event handler from a target. If callback isn't passed - all registered listeners are removed. If event isn't passed - all registered callbacks for all known events are removed (useful on destroying the target).

// remove handler the standard way
off(target, 'click', handler)

// remove handler for all registered events
off(target, handler)

// remove all events with provided suffix[es]
off(target, '.special')

emit(target, event, data?, options?)

Emit an event on a target. event can be a string or an Event instance. If target is an element then data is placed to e.details. options can define triggering params, eg. {bubbles: true}.

License

MIT © Dmitry Ivanov.

7.0.0

5 years ago

6.0.2

5 years ago

6.0.1

5 years ago

6.0.0

5 years ago

5.4.0

8 years ago

5.3.5

9 years ago

5.3.4

9 years ago

5.3.3

9 years ago

5.3.2

9 years ago

5.3.1

9 years ago

5.3.0

9 years ago

5.2.9

9 years ago

5.2.8

9 years ago

5.2.7

9 years ago

5.2.6

9 years ago

5.2.5

9 years ago

5.2.4

9 years ago

5.2.3

9 years ago

5.2.2

9 years ago

5.2.1

9 years ago

5.2.0

9 years ago

5.1.4

9 years ago

5.1.3

9 years ago

5.1.2

9 years ago

5.1.1

9 years ago

5.0.2

9 years ago

5.0.1

9 years ago

5.0.0

9 years ago

4.0.9

9 years ago

4.0.8

9 years ago

4.0.6

9 years ago

4.0.5

9 years ago

4.0.4

9 years ago

4.0.3

9 years ago

4.0.2

9 years ago

4.0.1

9 years ago

4.0.0

9 years ago

3.3.0

9 years ago

3.2.1

9 years ago

3.2.0

9 years ago

3.1.3

9 years ago

3.1.2

9 years ago

3.1.1

9 years ago

3.1.0

9 years ago

3.0.4

9 years ago

3.0.3

9 years ago

3.0.2

9 years ago

3.0.1

9 years ago

3.0.0

9 years ago

2.2.2

9 years ago

2.2.1

9 years ago

2.2.0

9 years ago

2.1.4

9 years ago

2.1.3

9 years ago

2.1.2

9 years ago

2.1.1

9 years ago

2.1.0

9 years ago

1.2.1

9 years ago

1.2.0

10 years ago

1.1.7

10 years ago

1.1.6

10 years ago

1.1.5

10 years ago

1.1.4

10 years ago

1.1.3

10 years ago

1.1.2

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago