@area17/a17-behaviors

0.4.4 • Public • Published

a17-behaviors

A framework for attaching JavaScript behaviors (interactions, events, manipulations) to DOM nodes.

<button data-behavior="showAlert">Click me</button>

With a corresponding behavior:

import { createBehavior } from '@area17/a17-behaviors';

const showAlert = createBehavior('showAlert',
    {
        alert(val) {
            window.alert('Hello world!');
        }
    },
    {
        init() {
            this.$node.addEventListener('click', this.alert);
        },
        destroy() {
            this.$node.removeEventListener('click', this.alert);
        }
    }
);

export default showAlert;

This would show an alert on click of the button. Note that this.$node is the DOM node with the data-behavior attribute.

For more detailed setup and explanation, see the project wiki.

Readme

Keywords

none

Package Sidebar

Install

npm i @area17/a17-behaviors

Weekly Downloads

231

Version

0.4.4

License

MIT

Unpacked Size

81.2 kB

Total Files

5

Last publish

Collaborators

  • ptrckvzn
  • quentinrenard
  • mrdoinel
  • 13twelve
  • m4n1ok
  • mazinoukah
  • mrtimbrook