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

Plugin

Reim can be extended using plugins. An example plugin would be like this:

const sayHello(options) {
    const message = options.message
    return (store) => {
        store.subscribe(state => {
            console.log('Hello! ', options.message)
            store.emit('said-hello', options.message)
        })
    }
}

Note that it returns a function. This enables us to accept plugin-specific options. Now to use it:

// Add plugins on store creation
const someStore = reim({}).plugin(sayBye('Once')).plugin(sayBye('Again!'))

someStore.increment()
// logs 'Hello! World'
// logs 'Bye! Once'
// logs 'Bye! Again!'
PreviousSubscribeNextEvent Emitter

Last updated 6 years ago