Reim
Github
2.0.0
2.0.0
  • Reim.js
  • Introduction
    • Motivation
    • Concepts
  • Guide
    • Store
    • setState
    • Subscribe
    • Plugin
    • Event Emitter
    • Use with React / Preact
    • Use with Vue
    • Use with Angular / Rxjs
  • Ecosystem
    • react-reim
    • reim-task
    • reim-reporter
    • reim-persist
    • Release Notes
Powered by GitBook
On this page
  1. Guide

Event Emitter

PreviousPluginNextUse with React / Preact

Last updated 5 years ago

Reim store is an , so you can freely use it for handling events

const emitter = reim({message: 'abc'})

emitter.on('test', () => {
  // … react to 'test' event
});

emitter.once('test', (...args) => {
  // … react to first 'test' event (invoked only once!)
});

emitter.emit('test', arg1, arg2/*…args*/); // Two above listeners invoked
emitter.emit('test', arg1, arg2/*…args*/); // Only first listener invoked

emitter.off('test', listener);              // Removed first listener
emitter.emit('test', arg1, arg2/*…args*/); // No listeners invoked

emitter.subscribe(() => emitter.emit('update-message'), state => state.message) // Emit on state change
Event Emitter