UNPKG

fsm-state-manager

Version:

A Flow FSM using a finite state machine pattern

29 lines (28 loc) 985 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SubscriptionManager = void 0; var SubscriptionManager = /** @class */ (function () { function SubscriptionManager() { this.subscribers = {}; this.idCounter = 0; } SubscriptionManager.prototype.subscribe = function (state, callback) { var _this = this; var id = "sub_".concat(this.idCounter++); this.subscribers[id] = { state: state, callback: callback }; return { unsubscribe: function () { delete _this.subscribers[id]; } }; }; SubscriptionManager.prototype.notify = function (state, newStateData) { for (var key in this.subscribers) { if (this.subscribers[key].state === state) { this.subscribers[key].callback(newStateData); } } }; return SubscriptionManager; }()); exports.SubscriptionManager = SubscriptionManager;