Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Latest commit

 

History

History
49 lines (36 loc) · 959 Bytes

README.md

File metadata and controls

49 lines (36 loc) · 959 Bytes

eventemittable

A composable EventEmitter for Stampit v3

Install

$ npm install stampit eventemittable --save

Stampit v3 or greater is a peer dependency of this module.

Usage

import EventEmittable from 'eventemittable';
import stampit from 'stampit';

// some stamp
const User = stampit.init((opts, {instance}) => {
  if (opts.name) {
    instance.name = opts.name;
  }
})
.props({
  name: {
    first: "(unnamed)",
    last: "(unnamed)"
  }
});

// an emittable version of some stamp
const EmittableUser = User.compose(EventEmittable);

// elsewhere...
const user = EmittableUser({name: {first: 'Guy', last: 'Fieri'}});
user.on('name', name => {
  console.log(`${name.first} ${name.last}`);
});
user.emit('name', user.name); // 'Guy Fieri'

Notes

Apologies to koresar. :D

License

© 2017 Christopher Hiller. Licensed Apache-2.0.