@jacobtipp/bloc-concurrency
TypeScript icon, indicating that this package has built-in type declarations

4.0.3 • Public • Published

@jacobtipp/bloc-concurrency

Installation

npm install @jacobtipp/bloc-concurrency

Event Transformers

bloc_concurrency provides an opinionated set of event transformers:

  • concurrent - process events concurrently
  • sequential - process events sequentially
  • restartable - process only the latest event and cancel previous event handlers

Usage

import { Bloc } from "@jacobtipp/bloc";
import { sequential } from "@jacobtipp/bloc-concurrency"

 abstract class CounterEvent {
  protected _!: void
 }

 class CounterIncrementEvent extends CounterEvent {}

export class CounterBloc extends Bloc<CounterEvent, number> {
  constructor() {
    super(0);

    this.on(
      CounterIncrementEvent,
      (event, emit) => {
        emit(this.state + 1);
      },
      /// Specify a custon event transformer from @jacobtipp/bloc-concurrency
      /// in this case events will be processed sequentially 
      sequential()
    );
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @jacobtipp/bloc-concurrency

Weekly Downloads

6

Version

4.0.3

License

MIT

Unpacked Size

5.8 kB

Total Files

7

Last publish

Collaborators

  • jacobtipp