UNPKG

kiss-js-bloc

Version:

Bloc type state management solution for typescript

55 lines (54 loc) 2 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var bloc_1 = require("./bloc"); // abstract class CounterEvent{} // class IncrementEvent extends CounterEvent { // public fNumber: number = 10; // } // class DecreamentEvent extends CounterEvent { // public fNumber: number = 10; // } var CounterBloc = /** @class */ (function (_super) { __extends(CounterBloc, _super); function CounterBloc() { return _super.call(this, 0) || this; } CounterBloc.prototype.increament = function () { return this.addNewState(this.state + 4); }; CounterBloc.prototype.decreament = function () { return this.addNewState(this.state - 4); }; return CounterBloc; }(bloc_1.Bloc)); var bloc = new CounterBloc(); bloc.on("increament", function (state) { bloc._state = bloc._state + state; }); bloc.on("decreament", function (state) { bloc._state = bloc._state - state; }); bloc.call("increament", 12); bloc.call("decreament", 2); console.log(bloc.state); // const events = require('events') // var myEmitter = new events.EventEmitter() // myEmitter.on(IncrementEvent, function(val: any) { // console.log(val) // }) // myEmitter.emit(IncrementEvent, "sadsd")