Skip to content

spatie/emits-change

Repository files navigation

emits-change

Latest Version on NPM Software License Build Status Code Climate

Plug-and-play node.js events integration to emit change events.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

npm install emits-change

This package uses the node.js events API. Make sure your javascript bundler can handles importing core node modules (e.g. Browserify does this).

Postcardware

You're free to use this package (it's MIT-licensed), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

The best postcards will get published on the open source page on our website.

Usage

Calling emitsChange on an object will add node's EventEmitter, a listen, an unlisten and an emitChange function to the prototype.

import emitsChange from 'emits-change'

class Emitter {
    constructor() {
        emitsChange(this)
    }
}

let emitter = new Emitter

function doSomethingOnChange() {
    console.log('hodor')
}

emitter.listen(doSomethingOnChange)

emitter.emitChange()
// => hodor

emitter.unlisten(doSomethingOnChange)

emitter.emitChange()
// => *nothing*

Testing

You can run the tests (ESLint & Mocha) with:

npm run test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email security@spatie.be instead of using the issue tracker.

Credits

About Spatie

Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

License

The MIT License (MIT). Please see License File for more information.

About

Plug-and-play node.js events integration to emit change events

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •