/simple-bloc

An implementation of bloc pattern for Javascript

Primary LanguageHTMLMIT LicenseMIT

Bloc implementation for javascript

How to use

  1. Install package $ npm install blocjs
  2. Inherit from the Bloc class:
import Bloc from 'blocjs';

class TestBloc extends Bloc {
  get initialState() {
    return {
      state: 'initial'
    };
  }
  async *mapEventsToState(event) {
    if (event === 'test:event') {
      yield new TestState();
    }
  }
}
  1. Use your bloc class and dispatch events to generate state changes:
const bloc = new TestBloc();
bloc.dispatch('test:event');

How to contribute