Coder Social home page Coder Social logo

wawa0584 / custom-event-js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shystruk/custom-event-js

0.0 0.0 0.0 17 KB

Event dispatcher based on the CustomEvent interface (works on browser)

Home Page: https://www.npmjs.com/package/custom-event-js

License: MIT License

JavaScript 100.00%

custom-event-js's Introduction

Custom Event Dispatcher Twitter URL

MIT Licence npm version Known Vulnerabilities

The Custom Event Dispatcher provides the ability to communicate inside your application by dispatching events and listening to them. It also runs polyfill for Internet Explorer 9 and higher. What is the CustomEvent interface you may find here.

Custom Event Dispatcher works in all popular browsers, including Internet Explorer 9 and higher.

Install

npm

npm install --save custom-event-js

yarn

yarn add custom-event-js --save

Example

import CustomEvent from 'custom-event-js'

// Listen event 'SHOW_NAME'
CustomEvent.on('SHOW_NAME', (data) => {
    console.log(data.detail) // { name: 'GitHub' }
})

// Dispatch event 'SHOW_NAME' with data
CustomEvent.dispatch('SHOW_NAME', { name: 'GitHub' })

// Remove event listener
CustomEvent.off('SHOW_NAME')

API

  • on(eventName, callback) add an appropriate event listener. When event gets fired callback will be called with detail argument

  • dispatch(eventName, detail) dispatch event to all event listeners

  • off(eventName) remove event listener

Contributing

Any contributions you make are greatly appreciated.

Please read the Contributions Guidelines before submitting a PR.

License

MIT © Vasyl Stokolosa

custom-event-js's People

Contributors

shystruk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.