diff --git a/packages/event/README.md b/packages/event/README.md index 4cd910287d2387e88bf0364c49eaede374840c91..ed56f226698e4aeff5ced2d94f0731078975c778 100644 --- a/packages/event/README.md +++ b/packages/event/README.md @@ -17,21 +17,18 @@ $ npm i @jsonql/event When using it directly in browser you have to do this: ```js -var eventService = new JsonqlEventService.JsonqlEventService() +var eventService = new JsonqlEvent() // the rest of the code ``` -I know it sucks big time, but that's the way how Typescript export when using name option with UMD ... -might change in the future when I figure out a better way, such as using a `jsonql` namespace -to encapsulate all the browser modules. But for now you have to kinda suck it up. - I would recommend that you don't use this module (Typescript is not as magical as most keep saying it is); -you should use [nb-event-service](https://npmjs.org/package/nb-event-service) instead. +you should use [nb-event-service](https://npmjs.org/package/nb-event-service) instead, if you only use this one module. +If you are using Typescript, then suck it up then ... For the other that use node build tool, just do this: ```js -import { JsonqlEventService } from '@jsonql/event' +import JsonqlEvent from '@jsonql/event' ``` ## API @@ -169,6 +166,29 @@ es.$on('some-event', function(num) { Or it will return `false` if there is nothing +#### $suspend + +This is a setter inside the class; When you set this to `true` it suspend all the `$trigger` and `call` operation. +They will be store inside a queue, and release when you set it to `false` + +```js +const evtSrv = new JsonqlEvent() + +evtSrv.$on('add-something', function(value) { + return value + 1; +}) +evtSrv.$suspend = true; + +evtSrv.$trigger('add-something', 100) + +evtSrv.$done === 101; // false + +evtSrv.$suspend = false; + +evtSrv.$done === 101; // true + +``` + --- diff --git a/packages/event/dist/jsonql-event-service.cjs.js b/packages/event/dist/jsonql-event.cjs.js similarity index 81% rename from packages/event/dist/jsonql-event-service.cjs.js rename to packages/event/dist/jsonql-event.cjs.js index 2a710aa189ee75309afcce9f234bb340e39e8a2e..a26e9b3c66afa7886147409eb4db37ce74db0dd1 100644 --- a/packages/event/dist/jsonql-event-service.cjs.js +++ b/packages/event/dist/jsonql-event.cjs.js @@ -1,7 +1,5 @@ 'use strict'; -Object.defineProperty(exports, '__esModule', { value: true }); - /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use @@ -42,18 +40,51 @@ function hashCode(fn) { return s.split("").reduce(function (a, b) { a = ((a << 5) - a) + b.charCodeAt(0); return a & a; }, 0) + ""; } -// break up the store related operation here -var JsonqlStoreService = /** @class */ (function () { +// the suspend ported from nb-event-service +// This is different from the nb-event-service +// instead of using object.defineProperty we just use the native ES6 setter +// with Typescript private +var JsonqlSuspend = /** @class */ (function () { + function JsonqlSuspend(logger) { + this.lastSuspendState = null; + this.suspend = null; + this.queue = new Set(); + } + Object.defineProperty(JsonqlSuspend.prototype, "$suspend", { + /** + * getter to get back the current suspend state + * @return {boolean} the suspend state + */ + get: function () { + return this.suspend; + }, + enumerable: true, + configurable: true + }); + /** + * @param {any} mapObj the Map object + * @return {array} transform to array to work with + */ + JsonqlSuspend.prototype.arrayFrom = function (mapObj) { + return Array.from(mapObj); + }; + return JsonqlSuspend; +}()); + +var JsonqlStoreService = /** @class */ (function (_super) { + __extends(JsonqlStoreService, _super); function JsonqlStoreService(logger) { + var _this = _super.call(this, logger) || this; // hack - this.logger = typeof logger === 'function' ? logger : function () { }; + _this.logger = typeof logger === 'function' ? logger : function () { }; // should this be WeakMap or should they be Map? - this.normalStore = new Map(); - this.lazyStore = new Map(); + _this.normalStore = new Map(); + _this.lazyStore = new Map(); // don't keep - this.keep = false; + _this.keep = false; // place holder, should this be a WeakSet? - this.result = []; + _this.result = []; + return _this; } /** * return all the listener from the event @@ -68,7 +99,7 @@ var JsonqlStoreService = /** @class */ (function () { this.logger('$get', full, this.normalStore); if (store.has(evt)) { return this - .mapToArr(store.get(evt)) + .arrayFrom(store.get(evt)) .map(function (l) { if (full) { return l; @@ -114,13 +145,6 @@ var JsonqlStoreService = /** @class */ (function () { ///////////////////////////////// // protected / PROTECTED METHODS // ///////////////////////////////// - /** - * @param {any} mapObj the Map object - * @return {array} transform to array to work with - */ - JsonqlStoreService.prototype.mapToArr = function (mapObj) { - return Array.from(mapObj); - }; /** * make sure we store the argument correctly * @param {*} arg could be array @@ -208,7 +232,7 @@ var JsonqlStoreService = /** @class */ (function () { * @return {boolean} true on exist */ JsonqlStoreService.prototype.checkContentExist = function (args, fnSet) { - var list = this.mapToArr(fnSet); + var list = this.arrayFrom(fnSet); return !!list .filter(function (value, index, array) { var hash = value[0]; @@ -247,7 +271,7 @@ var JsonqlStoreService = /** @class */ (function () { var store = this.lazyStore.get(evtName); if (store) { this.logger('checkTypeInLazyStore', store); - return !!this.mapToArr(store) + return !!this.arrayFrom(store) .filter(function (value, index, array) { var t = value[2]; return t !== type; @@ -354,17 +378,17 @@ var JsonqlStoreService = /** @class */ (function () { .filter(function (t) { return type === t; }).length; }; return JsonqlStoreService; -}()); +}(JsonqlSuspend)); // main -var JsonqlEventService = /** @class */ (function (_super) { - __extends(JsonqlEventService, _super); +var JsonqlEvent = /** @class */ (function (_super) { + __extends(JsonqlEvent, _super); /** * Create EventService instance * @param {configObj} config configuration object * @return {void} nothing - don't do :void this fuck typescript up what a lot of shit */ - function JsonqlEventService(logger) { + function JsonqlEvent(logger) { return _super.call(this, logger) || this; } /** @@ -375,7 +399,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} [context=null] to execute this call in * @return {number} the size of the store */ - JsonqlEventService.prototype.$on = function (evt, callback, context) { + JsonqlEvent.prototype.$on = function (evt, callback, context) { var _this = this; if (context === void 0) { context = null; } this.validate(callback, evt); @@ -415,7 +439,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} [context=null] the handler execute in * @return {number|boolean} result */ - JsonqlEventService.prototype.$once = function (evt, callback, context) { + JsonqlEvent.prototype.$once = function (evt, callback, context) { if (context === void 0) { context = null; } this.validate(callback, evt); var type = 'once'; @@ -434,7 +458,7 @@ var JsonqlEventService = /** @class */ (function (_super) { // so if in the middle they register any call with the same evt name // then this $once call will be fucked - add this to the documentation this.logger('$once', lazyStoreContent); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // should never have more than 1 var _a = list[0], payload = _a[0], ctx = _a[1], t = _a[2]; if (t && t !== type) { @@ -453,7 +477,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} [context=null] the context the event handler execute in * @return {boolean} true bind for first time, false already existed */ - JsonqlEventService.prototype.$only = function (evt, callback, context) { + JsonqlEvent.prototype.$only = function (evt, callback, context) { var _this = this; if (context === void 0) { context = null; } this.validate(callback, evt); @@ -471,7 +495,7 @@ var JsonqlEventService = /** @class */ (function (_super) { if (lazyStoreContent !== false) { // there are data store in lazy store this.logger('$only', evt + " found data in lazy store to execute"); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // $only allow to trigger this multiple time on the single handler list.forEach(function (l) { var payload = l[0], ctx = l[1], t = l[2]; @@ -491,7 +515,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} [context=null] exeucte context * @return {boolean} same as above */ - JsonqlEventService.prototype.$onlyOnce = function (evt, callback, context) { + JsonqlEvent.prototype.$onlyOnce = function (evt, callback, context) { if (context === void 0) { context = null; } this.validate(callback, evt); var type = 'onlyOnce'; @@ -506,7 +530,7 @@ var JsonqlEventService = /** @class */ (function (_super) { if (lazyStoreContent !== false) { // there are data store in lazy store this.logger('$onlyOnce', lazyStoreContent); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // should never have more than 1 var _a = list[0], payload = _a[0], ctx = _a[1], t = _a[2]; if (t && t !== 'onlyOnce') { @@ -526,7 +550,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {string} [type=on] what type of method to replace * @return {any} whatever the call method return */ - JsonqlEventService.prototype.$replace = function (evt, callback, context, type) { + JsonqlEvent.prototype.$replace = function (evt, callback, context, type) { if (context === void 0) { context = null; } if (type === void 0) { type = 'on'; } this.$off(evt); @@ -542,7 +566,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {string} [type=false] if pass this then we need to add type to store too * @return {number} if it has been execute how many times */ - JsonqlEventService.prototype.$trigger = function (evt, payload, context, type) { + JsonqlEvent.prototype.$trigger = function (evt, payload, context, type) { if (payload === void 0) { payload = []; } if (context === void 0) { context = null; } if (type === void 0) { type = false; } @@ -550,10 +574,14 @@ var JsonqlEventService = /** @class */ (function (_super) { var found = 0; // first check the normal store var nStore = this.normalStore; - this.logger('$trigger', nStore); + this.logger('$trigger, from normalStore: ', nStore); if (nStore.has(evt)) { - this.logger('$trigger', evt, 'found'); - var nSet = this.mapToArr(nStore.get(evt)); + var added = this.$queue(evt, payload, context, type); + this.logger('$trigger', evt, 'found; add to queue: ', added); + if (added === true) { + return found; // just exit + } + var nSet = this.arrayFrom(nStore.get(evt)); var ctn = nSet.length; var hasOnce = false; // let hasOnly = false; @@ -584,7 +612,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} context what context callback execute in * @return {*} from $trigger */ - JsonqlEventService.prototype.$call = function (evt, params, type, context) { + JsonqlEvent.prototype.$call = function (evt, params, type, context) { if (type === void 0) { type = false; } if (context === void 0) { context = null; } this.validateEvt(evt); @@ -597,7 +625,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {string} evt name * @return {boolean} true actually delete something */ - JsonqlEventService.prototype.$off = function (evt) { + JsonqlEvent.prototype.$off = function (evt) { this.validateEvt(evt); var stores = [this.lazyStore, this.normalStore]; var found = false; @@ -614,7 +642,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {string} type the 4 types * @return {*} the method */ - JsonqlEventService.prototype.getMethodBy = function (type) { + JsonqlEvent.prototype.getMethodBy = function (type) { switch (type) { case 'on': return this.$on; @@ -628,7 +656,67 @@ var JsonqlEventService = /** @class */ (function (_super) { throw new Error(type + " is not supported!"); } }; - return JsonqlEventService; + /** + * Add $trigger args to the queue during suspend state + * @param {array} args from the $trigger call parameters + * @return {boolean} true when added + */ + JsonqlEvent.prototype.$queue = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var added = false; + if (this.suspend) { + this.queue.add(args); + added = true; + } + return added; + }; + /** + * whenever the suspend change from true to false + * then we check the queue to see if there is anything to do + * @return {boolean} true if there is queue + */ + JsonqlEvent.prototype.releaseQueue = function () { + var _this = this; + var size = this.queue.size; + if (size > 0) { + var queue = this.arrayFrom(this.queue); + this.queue.clear(); + queue.forEach(function (args) { + Reflect.apply(_this.$trigger, _this, args); + }); + } + return !!size; + }; + Object.defineProperty(JsonqlEvent.prototype, "$suspend", { + /** + * This is the main interface to see if anything happens + * @param {boolean} state to change the suspend state + * @return {boolean} what comes in what goes out + */ + set: function (state) { + var _this = this; + if (typeof state !== 'boolean') { + throw new Error("Typescript is a fucking joke! BTW we want a Boolean which fucking Typescript can't figure it out!!!! " + typeof state); + } + this.suspend = state; + if (state !== this.lastSuspendState) { + if (this.lastSuspendState === true && this.suspend === false) { + setTimeout(function () { + _this.releaseQueue(); + }, 1); + } + } + this.lastSuspendState = state; + }, + enumerable: true, + configurable: true + }); + return JsonqlEvent; }(JsonqlStoreService)); -exports.JsonqlEventService = JsonqlEventService; +// The top level for @jsonql/event + +module.exports = JsonqlEvent; diff --git a/packages/event/dist/jsonql-event.d.ts b/packages/event/dist/jsonql-event.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..dffd0e6015dfb6af5ab212cd8a25f5ee6ac4858f --- /dev/null +++ b/packages/event/dist/jsonql-event.d.ts @@ -0,0 +1 @@ +declare module "@jsonql/event" diff --git a/packages/event/dist/jsonql-event-service.es.js b/packages/event/dist/jsonql-event.es.js similarity index 81% rename from packages/event/dist/jsonql-event-service.es.js rename to packages/event/dist/jsonql-event.es.js index b952283bfbf82d72b547426a72a871a4c6d9a0d5..df8db154e8b6eb76bfb526f0a2439f672ae21354 100644 --- a/packages/event/dist/jsonql-event-service.es.js +++ b/packages/event/dist/jsonql-event.es.js @@ -38,18 +38,51 @@ function hashCode(fn) { return s.split("").reduce(function (a, b) { a = ((a << 5) - a) + b.charCodeAt(0); return a & a; }, 0) + ""; } -// break up the store related operation here -var JsonqlStoreService = /** @class */ (function () { +// the suspend ported from nb-event-service +// This is different from the nb-event-service +// instead of using object.defineProperty we just use the native ES6 setter +// with Typescript private +var JsonqlSuspend = /** @class */ (function () { + function JsonqlSuspend(logger) { + this.lastSuspendState = null; + this.suspend = null; + this.queue = new Set(); + } + Object.defineProperty(JsonqlSuspend.prototype, "$suspend", { + /** + * getter to get back the current suspend state + * @return {boolean} the suspend state + */ + get: function () { + return this.suspend; + }, + enumerable: true, + configurable: true + }); + /** + * @param {any} mapObj the Map object + * @return {array} transform to array to work with + */ + JsonqlSuspend.prototype.arrayFrom = function (mapObj) { + return Array.from(mapObj); + }; + return JsonqlSuspend; +}()); + +var JsonqlStoreService = /** @class */ (function (_super) { + __extends(JsonqlStoreService, _super); function JsonqlStoreService(logger) { + var _this = _super.call(this, logger) || this; // hack - this.logger = typeof logger === 'function' ? logger : function () { }; + _this.logger = typeof logger === 'function' ? logger : function () { }; // should this be WeakMap or should they be Map? - this.normalStore = new Map(); - this.lazyStore = new Map(); + _this.normalStore = new Map(); + _this.lazyStore = new Map(); // don't keep - this.keep = false; + _this.keep = false; // place holder, should this be a WeakSet? - this.result = []; + _this.result = []; + return _this; } /** * return all the listener from the event @@ -64,7 +97,7 @@ var JsonqlStoreService = /** @class */ (function () { this.logger('$get', full, this.normalStore); if (store.has(evt)) { return this - .mapToArr(store.get(evt)) + .arrayFrom(store.get(evt)) .map(function (l) { if (full) { return l; @@ -110,13 +143,6 @@ var JsonqlStoreService = /** @class */ (function () { ///////////////////////////////// // protected / PROTECTED METHODS // ///////////////////////////////// - /** - * @param {any} mapObj the Map object - * @return {array} transform to array to work with - */ - JsonqlStoreService.prototype.mapToArr = function (mapObj) { - return Array.from(mapObj); - }; /** * make sure we store the argument correctly * @param {*} arg could be array @@ -204,7 +230,7 @@ var JsonqlStoreService = /** @class */ (function () { * @return {boolean} true on exist */ JsonqlStoreService.prototype.checkContentExist = function (args, fnSet) { - var list = this.mapToArr(fnSet); + var list = this.arrayFrom(fnSet); return !!list .filter(function (value, index, array) { var hash = value[0]; @@ -243,7 +269,7 @@ var JsonqlStoreService = /** @class */ (function () { var store = this.lazyStore.get(evtName); if (store) { this.logger('checkTypeInLazyStore', store); - return !!this.mapToArr(store) + return !!this.arrayFrom(store) .filter(function (value, index, array) { var t = value[2]; return t !== type; @@ -350,17 +376,17 @@ var JsonqlStoreService = /** @class */ (function () { .filter(function (t) { return type === t; }).length; }; return JsonqlStoreService; -}()); +}(JsonqlSuspend)); // main -var JsonqlEventService = /** @class */ (function (_super) { - __extends(JsonqlEventService, _super); +var JsonqlEvent = /** @class */ (function (_super) { + __extends(JsonqlEvent, _super); /** * Create EventService instance * @param {configObj} config configuration object * @return {void} nothing - don't do :void this fuck typescript up what a lot of shit */ - function JsonqlEventService(logger) { + function JsonqlEvent(logger) { return _super.call(this, logger) || this; } /** @@ -371,7 +397,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} [context=null] to execute this call in * @return {number} the size of the store */ - JsonqlEventService.prototype.$on = function (evt, callback, context) { + JsonqlEvent.prototype.$on = function (evt, callback, context) { var _this = this; if (context === void 0) { context = null; } this.validate(callback, evt); @@ -411,7 +437,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} [context=null] the handler execute in * @return {number|boolean} result */ - JsonqlEventService.prototype.$once = function (evt, callback, context) { + JsonqlEvent.prototype.$once = function (evt, callback, context) { if (context === void 0) { context = null; } this.validate(callback, evt); var type = 'once'; @@ -430,7 +456,7 @@ var JsonqlEventService = /** @class */ (function (_super) { // so if in the middle they register any call with the same evt name // then this $once call will be fucked - add this to the documentation this.logger('$once', lazyStoreContent); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // should never have more than 1 var _a = list[0], payload = _a[0], ctx = _a[1], t = _a[2]; if (t && t !== type) { @@ -449,7 +475,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} [context=null] the context the event handler execute in * @return {boolean} true bind for first time, false already existed */ - JsonqlEventService.prototype.$only = function (evt, callback, context) { + JsonqlEvent.prototype.$only = function (evt, callback, context) { var _this = this; if (context === void 0) { context = null; } this.validate(callback, evt); @@ -467,7 +493,7 @@ var JsonqlEventService = /** @class */ (function (_super) { if (lazyStoreContent !== false) { // there are data store in lazy store this.logger('$only', evt + " found data in lazy store to execute"); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // $only allow to trigger this multiple time on the single handler list.forEach(function (l) { var payload = l[0], ctx = l[1], t = l[2]; @@ -487,7 +513,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} [context=null] exeucte context * @return {boolean} same as above */ - JsonqlEventService.prototype.$onlyOnce = function (evt, callback, context) { + JsonqlEvent.prototype.$onlyOnce = function (evt, callback, context) { if (context === void 0) { context = null; } this.validate(callback, evt); var type = 'onlyOnce'; @@ -502,7 +528,7 @@ var JsonqlEventService = /** @class */ (function (_super) { if (lazyStoreContent !== false) { // there are data store in lazy store this.logger('$onlyOnce', lazyStoreContent); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // should never have more than 1 var _a = list[0], payload = _a[0], ctx = _a[1], t = _a[2]; if (t && t !== 'onlyOnce') { @@ -522,7 +548,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {string} [type=on] what type of method to replace * @return {any} whatever the call method return */ - JsonqlEventService.prototype.$replace = function (evt, callback, context, type) { + JsonqlEvent.prototype.$replace = function (evt, callback, context, type) { if (context === void 0) { context = null; } if (type === void 0) { type = 'on'; } this.$off(evt); @@ -538,7 +564,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {string} [type=false] if pass this then we need to add type to store too * @return {number} if it has been execute how many times */ - JsonqlEventService.prototype.$trigger = function (evt, payload, context, type) { + JsonqlEvent.prototype.$trigger = function (evt, payload, context, type) { if (payload === void 0) { payload = []; } if (context === void 0) { context = null; } if (type === void 0) { type = false; } @@ -546,10 +572,14 @@ var JsonqlEventService = /** @class */ (function (_super) { var found = 0; // first check the normal store var nStore = this.normalStore; - this.logger('$trigger', nStore); + this.logger('$trigger, from normalStore: ', nStore); if (nStore.has(evt)) { - this.logger('$trigger', evt, 'found'); - var nSet = this.mapToArr(nStore.get(evt)); + var added = this.$queue(evt, payload, context, type); + this.logger('$trigger', evt, 'found; add to queue: ', added); + if (added === true) { + return found; // just exit + } + var nSet = this.arrayFrom(nStore.get(evt)); var ctn = nSet.length; var hasOnce = false; // let hasOnly = false; @@ -580,7 +610,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {object} context what context callback execute in * @return {*} from $trigger */ - JsonqlEventService.prototype.$call = function (evt, params, type, context) { + JsonqlEvent.prototype.$call = function (evt, params, type, context) { if (type === void 0) { type = false; } if (context === void 0) { context = null; } this.validateEvt(evt); @@ -593,7 +623,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {string} evt name * @return {boolean} true actually delete something */ - JsonqlEventService.prototype.$off = function (evt) { + JsonqlEvent.prototype.$off = function (evt) { this.validateEvt(evt); var stores = [this.lazyStore, this.normalStore]; var found = false; @@ -610,7 +640,7 @@ var JsonqlEventService = /** @class */ (function (_super) { * @param {string} type the 4 types * @return {*} the method */ - JsonqlEventService.prototype.getMethodBy = function (type) { + JsonqlEvent.prototype.getMethodBy = function (type) { switch (type) { case 'on': return this.$on; @@ -624,7 +654,67 @@ var JsonqlEventService = /** @class */ (function (_super) { throw new Error(type + " is not supported!"); } }; - return JsonqlEventService; + /** + * Add $trigger args to the queue during suspend state + * @param {array} args from the $trigger call parameters + * @return {boolean} true when added + */ + JsonqlEvent.prototype.$queue = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var added = false; + if (this.suspend) { + this.queue.add(args); + added = true; + } + return added; + }; + /** + * whenever the suspend change from true to false + * then we check the queue to see if there is anything to do + * @return {boolean} true if there is queue + */ + JsonqlEvent.prototype.releaseQueue = function () { + var _this = this; + var size = this.queue.size; + if (size > 0) { + var queue = this.arrayFrom(this.queue); + this.queue.clear(); + queue.forEach(function (args) { + Reflect.apply(_this.$trigger, _this, args); + }); + } + return !!size; + }; + Object.defineProperty(JsonqlEvent.prototype, "$suspend", { + /** + * This is the main interface to see if anything happens + * @param {boolean} state to change the suspend state + * @return {boolean} what comes in what goes out + */ + set: function (state) { + var _this = this; + if (typeof state !== 'boolean') { + throw new Error("Typescript is a fucking joke! BTW we want a Boolean which fucking Typescript can't figure it out!!!! " + typeof state); + } + this.suspend = state; + if (state !== this.lastSuspendState) { + if (this.lastSuspendState === true && this.suspend === false) { + setTimeout(function () { + _this.releaseQueue(); + }, 1); + } + } + this.lastSuspendState = state; + }, + enumerable: true, + configurable: true + }); + return JsonqlEvent; }(JsonqlStoreService)); -export { JsonqlEventService }; +// The top level for @jsonql/event + +export default JsonqlEvent; diff --git a/packages/event/dist/jsonql-event-service.umd.js b/packages/event/dist/jsonql-event.umd.js similarity index 81% rename from packages/event/dist/jsonql-event-service.umd.js rename to packages/event/dist/jsonql-event.umd.js index 654592e2270e61d06b7e8e78243bba4c9cb5ea6f..9b24f5d19e5bf7c7b3d4a25b64584989b9f4af3e 100644 --- a/packages/event/dist/jsonql-event-service.umd.js +++ b/packages/event/dist/jsonql-event.umd.js @@ -1,8 +1,8 @@ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : - typeof define === 'function' && define.amd ? define(['exports'], factory) : - (global = global || self, factory(global.JsonqlEventService = {})); -}(this, function (exports) { 'use strict'; + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = global || self, global.JsonqlEvent = factory()); +}(this, function () { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. @@ -44,18 +44,51 @@ return s.split("").reduce(function (a, b) { a = ((a << 5) - a) + b.charCodeAt(0); return a & a; }, 0) + ""; } - // break up the store related operation here - var JsonqlStoreService = /** @class */ (function () { + // the suspend ported from nb-event-service + // This is different from the nb-event-service + // instead of using object.defineProperty we just use the native ES6 setter + // with Typescript private + var JsonqlSuspend = /** @class */ (function () { + function JsonqlSuspend(logger) { + this.lastSuspendState = null; + this.suspend = null; + this.queue = new Set(); + } + Object.defineProperty(JsonqlSuspend.prototype, "$suspend", { + /** + * getter to get back the current suspend state + * @return {boolean} the suspend state + */ + get: function () { + return this.suspend; + }, + enumerable: true, + configurable: true + }); + /** + * @param {any} mapObj the Map object + * @return {array} transform to array to work with + */ + JsonqlSuspend.prototype.arrayFrom = function (mapObj) { + return Array.from(mapObj); + }; + return JsonqlSuspend; + }()); + + var JsonqlStoreService = /** @class */ (function (_super) { + __extends(JsonqlStoreService, _super); function JsonqlStoreService(logger) { + var _this = _super.call(this, logger) || this; // hack - this.logger = typeof logger === 'function' ? logger : function () { }; + _this.logger = typeof logger === 'function' ? logger : function () { }; // should this be WeakMap or should they be Map? - this.normalStore = new Map(); - this.lazyStore = new Map(); + _this.normalStore = new Map(); + _this.lazyStore = new Map(); // don't keep - this.keep = false; + _this.keep = false; // place holder, should this be a WeakSet? - this.result = []; + _this.result = []; + return _this; } /** * return all the listener from the event @@ -70,7 +103,7 @@ this.logger('$get', full, this.normalStore); if (store.has(evt)) { return this - .mapToArr(store.get(evt)) + .arrayFrom(store.get(evt)) .map(function (l) { if (full) { return l; @@ -116,13 +149,6 @@ ///////////////////////////////// // protected / PROTECTED METHODS // ///////////////////////////////// - /** - * @param {any} mapObj the Map object - * @return {array} transform to array to work with - */ - JsonqlStoreService.prototype.mapToArr = function (mapObj) { - return Array.from(mapObj); - }; /** * make sure we store the argument correctly * @param {*} arg could be array @@ -210,7 +236,7 @@ * @return {boolean} true on exist */ JsonqlStoreService.prototype.checkContentExist = function (args, fnSet) { - var list = this.mapToArr(fnSet); + var list = this.arrayFrom(fnSet); return !!list .filter(function (value, index, array) { var hash = value[0]; @@ -249,7 +275,7 @@ var store = this.lazyStore.get(evtName); if (store) { this.logger('checkTypeInLazyStore', store); - return !!this.mapToArr(store) + return !!this.arrayFrom(store) .filter(function (value, index, array) { var t = value[2]; return t !== type; @@ -356,17 +382,17 @@ .filter(function (t) { return type === t; }).length; }; return JsonqlStoreService; - }()); + }(JsonqlSuspend)); // main - var JsonqlEventService = /** @class */ (function (_super) { - __extends(JsonqlEventService, _super); + var JsonqlEvent = /** @class */ (function (_super) { + __extends(JsonqlEvent, _super); /** * Create EventService instance * @param {configObj} config configuration object * @return {void} nothing - don't do :void this fuck typescript up what a lot of shit */ - function JsonqlEventService(logger) { + function JsonqlEvent(logger) { return _super.call(this, logger) || this; } /** @@ -377,7 +403,7 @@ * @param {object} [context=null] to execute this call in * @return {number} the size of the store */ - JsonqlEventService.prototype.$on = function (evt, callback, context) { + JsonqlEvent.prototype.$on = function (evt, callback, context) { var _this = this; if (context === void 0) { context = null; } this.validate(callback, evt); @@ -417,7 +443,7 @@ * @param {object} [context=null] the handler execute in * @return {number|boolean} result */ - JsonqlEventService.prototype.$once = function (evt, callback, context) { + JsonqlEvent.prototype.$once = function (evt, callback, context) { if (context === void 0) { context = null; } this.validate(callback, evt); var type = 'once'; @@ -436,7 +462,7 @@ // so if in the middle they register any call with the same evt name // then this $once call will be fucked - add this to the documentation this.logger('$once', lazyStoreContent); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // should never have more than 1 var _a = list[0], payload = _a[0], ctx = _a[1], t = _a[2]; if (t && t !== type) { @@ -455,7 +481,7 @@ * @param {object} [context=null] the context the event handler execute in * @return {boolean} true bind for first time, false already existed */ - JsonqlEventService.prototype.$only = function (evt, callback, context) { + JsonqlEvent.prototype.$only = function (evt, callback, context) { var _this = this; if (context === void 0) { context = null; } this.validate(callback, evt); @@ -473,7 +499,7 @@ if (lazyStoreContent !== false) { // there are data store in lazy store this.logger('$only', evt + " found data in lazy store to execute"); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // $only allow to trigger this multiple time on the single handler list.forEach(function (l) { var payload = l[0], ctx = l[1], t = l[2]; @@ -493,7 +519,7 @@ * @param {object} [context=null] exeucte context * @return {boolean} same as above */ - JsonqlEventService.prototype.$onlyOnce = function (evt, callback, context) { + JsonqlEvent.prototype.$onlyOnce = function (evt, callback, context) { if (context === void 0) { context = null; } this.validate(callback, evt); var type = 'onlyOnce'; @@ -508,7 +534,7 @@ if (lazyStoreContent !== false) { // there are data store in lazy store this.logger('$onlyOnce', lazyStoreContent); - var list = this.mapToArr(lazyStoreContent); + var list = this.arrayFrom(lazyStoreContent); // should never have more than 1 var _a = list[0], payload = _a[0], ctx = _a[1], t = _a[2]; if (t && t !== 'onlyOnce') { @@ -528,7 +554,7 @@ * @param {string} [type=on] what type of method to replace * @return {any} whatever the call method return */ - JsonqlEventService.prototype.$replace = function (evt, callback, context, type) { + JsonqlEvent.prototype.$replace = function (evt, callback, context, type) { if (context === void 0) { context = null; } if (type === void 0) { type = 'on'; } this.$off(evt); @@ -544,7 +570,7 @@ * @param {string} [type=false] if pass this then we need to add type to store too * @return {number} if it has been execute how many times */ - JsonqlEventService.prototype.$trigger = function (evt, payload, context, type) { + JsonqlEvent.prototype.$trigger = function (evt, payload, context, type) { if (payload === void 0) { payload = []; } if (context === void 0) { context = null; } if (type === void 0) { type = false; } @@ -552,10 +578,14 @@ var found = 0; // first check the normal store var nStore = this.normalStore; - this.logger('$trigger', nStore); + this.logger('$trigger, from normalStore: ', nStore); if (nStore.has(evt)) { - this.logger('$trigger', evt, 'found'); - var nSet = this.mapToArr(nStore.get(evt)); + var added = this.$queue(evt, payload, context, type); + this.logger('$trigger', evt, 'found; add to queue: ', added); + if (added === true) { + return found; // just exit + } + var nSet = this.arrayFrom(nStore.get(evt)); var ctn = nSet.length; var hasOnce = false; // let hasOnly = false; @@ -586,7 +616,7 @@ * @param {object} context what context callback execute in * @return {*} from $trigger */ - JsonqlEventService.prototype.$call = function (evt, params, type, context) { + JsonqlEvent.prototype.$call = function (evt, params, type, context) { if (type === void 0) { type = false; } if (context === void 0) { context = null; } this.validateEvt(evt); @@ -599,7 +629,7 @@ * @param {string} evt name * @return {boolean} true actually delete something */ - JsonqlEventService.prototype.$off = function (evt) { + JsonqlEvent.prototype.$off = function (evt) { this.validateEvt(evt); var stores = [this.lazyStore, this.normalStore]; var found = false; @@ -616,7 +646,7 @@ * @param {string} type the 4 types * @return {*} the method */ - JsonqlEventService.prototype.getMethodBy = function (type) { + JsonqlEvent.prototype.getMethodBy = function (type) { switch (type) { case 'on': return this.$on; @@ -630,11 +660,69 @@ throw new Error(type + " is not supported!"); } }; - return JsonqlEventService; + /** + * Add $trigger args to the queue during suspend state + * @param {array} args from the $trigger call parameters + * @return {boolean} true when added + */ + JsonqlEvent.prototype.$queue = function () { + var args = []; + for (var _i = 0; _i < arguments.length; _i++) { + args[_i] = arguments[_i]; + } + var added = false; + if (this.suspend) { + this.queue.add(args); + added = true; + } + return added; + }; + /** + * whenever the suspend change from true to false + * then we check the queue to see if there is anything to do + * @return {boolean} true if there is queue + */ + JsonqlEvent.prototype.releaseQueue = function () { + var _this = this; + var size = this.queue.size; + if (size > 0) { + var queue = this.arrayFrom(this.queue); + this.queue.clear(); + queue.forEach(function (args) { + Reflect.apply(_this.$trigger, _this, args); + }); + } + return !!size; + }; + Object.defineProperty(JsonqlEvent.prototype, "$suspend", { + /** + * This is the main interface to see if anything happens + * @param {boolean} state to change the suspend state + * @return {boolean} what comes in what goes out + */ + set: function (state) { + var _this = this; + if (typeof state !== 'boolean') { + throw new Error("Typescript is a fucking joke! BTW we want a Boolean which fucking Typescript can't figure it out!!!! " + typeof state); + } + this.suspend = state; + if (state !== this.lastSuspendState) { + if (this.lastSuspendState === true && this.suspend === false) { + setTimeout(function () { + _this.releaseQueue(); + }, 1); + } + } + this.lastSuspendState = state; + }, + enumerable: true, + configurable: true + }); + return JsonqlEvent; }(JsonqlStoreService)); - exports.JsonqlEventService = JsonqlEventService; + // The top level for @jsonql/event - Object.defineProperty(exports, '__esModule', { value: true }); + return JsonqlEvent; })); diff --git a/packages/event/index.ts b/packages/event/index.ts index 879d21b2b45dbe95afcc7785ac1c2bd5098ba64e..25ae74ef870f424b2cf66687ba26d60bf069fd5e 100644 --- a/packages/event/index.ts +++ b/packages/event/index.ts @@ -1,5 +1,6 @@ // The top level for @jsonql/event -// The class file has no default export therefore here you will ended up with named export -export * from './src/event-service'; -// what a mess! you can just do a direct export! if you use default you ended up with a stupid .default name +// The class file has no default export therefore here you will ended up with named export +import JsonqlEvent from './src/event-service'; +// You have to do this in 2 steps to get rip of the .default from cjs! +export default JsonqlEvent; diff --git a/packages/event/package.json b/packages/event/package.json index c2661d973e0ff3d90084bb58b508209eb6ee1f8c..2e9b868b87804ff319902e28f78e99c822213345 100644 --- a/packages/event/package.json +++ b/packages/event/package.json @@ -1,11 +1,11 @@ { "name": "@jsonql/event", - "version": "1.1.0", + "version": "1.2.0", "description": "Ported from nb-event-service rewritten with Typescript", - "main": "dist/jsonql-event-service.cjs.js", - "browser": "dist/jsonql-event-service.umd.js", - "module": "dist/jsonql-event-service.es.js", - "types": "dist/index.d.ts", + "main": "dist/jsonql-event.cjs.js", + "browser": "dist/jsonql-event.umd.js", + "module": "dist/jsonql-event.es.js", + "types": "dist/jsonql-event.d.ts", "files": [ "dist", "index.ts" @@ -14,9 +14,10 @@ "test": "DEBUG=nb-event-service* ava --verbose", "build": "rollup -c", "dev": "rollup -cw", - "test:basic": "DEBUG=nb-event-service* ava ./tests/basic.test.js", "test:browser": "node ./tests/fixtures/browser.js", - "test:once-problem": "DEBUG=nb-event-service* ava ./tests/once-problem.test.js" + "test:basic": "DEBUG=nb-event-service* ava ./tests/basic.test.js", + "test:once-problem": "DEBUG=nb-event-service* ava ./tests/once-problem.test.js", + "test:suspend": "DEBUG=nb-event-service* ava ./tests/suspend.test.js" }, "keywords": [ "jsonql", @@ -37,8 +38,8 @@ "devDependencies": { "ava": "^2.2.0", "debug": "^4.1.1", - "rollup": "^1.16.7", - "rollup-plugin-typescript2": "^0.22.0", + "rollup": "^1.17.0", + "rollup-plugin-typescript2": "^0.22.1", "server-io-core": "^1.2.0-beta.2", "ts-node": "^8.3.0", "typescript": "^3.5.3" diff --git a/packages/event/rollup.config.js b/packages/event/rollup.config.js index eed255461683ae34e7ada88f39e064948addba0f..e82b1dfd12e0462ee6ba56d6e9dcdfb3dfb5a91f 100644 --- a/packages/event/rollup.config.js +++ b/packages/event/rollup.config.js @@ -15,7 +15,7 @@ export default { { file: pkg.browser, format: 'umd', - name: 'JsonqlEventService' + name: 'JsonqlEvent' } ], external: [ diff --git a/packages/event/src/event-service.ts b/packages/event/src/event-service.ts index 65be7d873f952d337b3ddc66b9392940d88a8f7a..d7b8c8e20f6ade7b8bab797284179c512d1e5701 100644 --- a/packages/event/src/event-service.ts +++ b/packages/event/src/event-service.ts @@ -3,7 +3,7 @@ import './interfaces.ts'; import JsonqlStoreService from './store-service'; // main -export class JsonqlEventService extends JsonqlStoreService { +export default class JsonqlEvent extends JsonqlStoreService { /** * Create EventService instance @@ -79,7 +79,7 @@ export class JsonqlEventService extends JsonqlStoreService { // so if in the middle they register any call with the same evt name // then this $once call will be fucked - add this to the documentation this.logger('$once', lazyStoreContent) - const list = this.mapToArr(lazyStoreContent) + const list = this.arrayFrom(lazyStoreContent) // should never have more than 1 const [ payload, ctx, t ] = list[0] if (t && t !== type) { @@ -115,7 +115,7 @@ export class JsonqlEventService extends JsonqlStoreService { if (lazyStoreContent !== false) { // there are data store in lazy store this.logger('$only', `${evt} found data in lazy store to execute`) - const list = this.mapToArr(lazyStoreContent) + const list = this.arrayFrom(lazyStoreContent) // $only allow to trigger this multiple time on the single handler list.forEach( l => { const [ payload, ctx, t ] = l; @@ -150,7 +150,7 @@ export class JsonqlEventService extends JsonqlStoreService { if (lazyStoreContent !== false) { // there are data store in lazy store this.logger('$onlyOnce', lazyStoreContent) - const list = this.mapToArr(lazyStoreContent) + const list = this.arrayFrom(lazyStoreContent) // should never have more than 1 const [ payload, ctx, t ] = list[0] if (t && t !== 'onlyOnce') { @@ -191,10 +191,14 @@ export class JsonqlEventService extends JsonqlStoreService { let found = 0; // first check the normal store let nStore = this.normalStore; - this.logger('$trigger', nStore) + this.logger('$trigger, from normalStore: ', nStore) if (nStore.has(evt)) { - this.logger('$trigger', evt, 'found') - let nSet = this.mapToArr(nStore.get(evt)) + let added = this.$queue(evt, payload, context, type) + this.logger('$trigger', evt, 'found; add to queue: ', added) + if (added === true) { + return found; // just exit + } + let nSet = this.arrayFrom(nStore.get(evt)) let ctn = nSet.length; let hasOnce = false; // let hasOnly = false; @@ -251,9 +255,6 @@ export class JsonqlEventService extends JsonqlStoreService { return found; } - - - /** * When using ES6 you just need this[$+type] but typescript no such luck * @param {string} type the 4 types @@ -273,5 +274,56 @@ export class JsonqlEventService extends JsonqlStoreService { throw new Error(`${type} is not supported!`) } } + /** + * Add $trigger args to the queue during suspend state + * @param {array} args from the $trigger call parameters + * @return {boolean} true when added + */ + private $queue(...args: any[]): boolean { + let added = false; + if (this.suspend) { + this.queue.add(args) + added = true; + } + return added; + } + + /** + * whenever the suspend change from true to false + * then we check the queue to see if there is anything to do + * @return {boolean} true if there is queue + */ + private releaseQueue(): boolean { + let size = this.queue.size; + if (size > 0) { + let queue = this.arrayFrom(this.queue) + this.queue.clear() + queue.forEach(args => { + Reflect.apply(this.$trigger, this, args) + }) + } + return !!size; + } + + /** + * This is the main interface to see if anything happens + * @param {boolean} state to change the suspend state + * @return {boolean} what comes in what goes out + */ + public set $suspend(state: boolean) { + if (typeof state !== 'boolean') { + throw new Error(`Typescript is a fucking joke! BTW we want a Boolean which fucking Typescript can't figure it out!!!! ${typeof state}`) + } + this.suspend = state; + if (state !== this.lastSuspendState) { + if (this.lastSuspendState === true && this.suspend === false) { + setTimeout(() => { + this.releaseQueue() + }, 1) + } + } + this.lastSuspendState = state; + } + } diff --git a/packages/event/src/hash-code.d.ts b/packages/event/src/hash-code.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..6c6874113efa2def921cca8e714b850b1e33c29b --- /dev/null +++ b/packages/event/src/hash-code.d.ts @@ -0,0 +1,7 @@ +/** + * generate a 32bit hash based on the function.toString() + * _from http://stackoverflow.com/questions/7616461/generate-a-hash-_from-string-in-javascript-jquery + * @param {function} fn the converted to string function + * @return {string} the hashed function string + */ +export default function hashCode(fn: Function): String; diff --git a/packages/event/src/interfaces.ts b/packages/event/src/interfaces.ts index 82154f0104aec72bd087d855c5a3c339f851d0e8..6000128fc659718b5701ac2780bd9d5ecfff226d 100644 --- a/packages/event/src/interfaces.ts +++ b/packages/event/src/interfaces.ts @@ -4,6 +4,7 @@ interface myCallbackType { (myArgument: string): void } + /* @TODO interface configObj { diff --git a/packages/event/src/store-service.ts b/packages/event/src/store-service.ts index 1509457d8462ea7a864aadc743e08053a4678055..71ea27e27783bb1ce9e0687b172e4c39cddd07f9 100644 --- a/packages/event/src/store-service.ts +++ b/packages/event/src/store-service.ts @@ -1,8 +1,9 @@ // break up the store related operation here // because the class is getting way too big now -import hashFnToKey from './hash-code'; +import hashFnToKey from './hash-code' +import JsonqlSuspend from './suspend' -export default class JsonqlStoreService { +export default class JsonqlStoreService extends JsonqlSuspend { // public props keep: boolean; // protected props @@ -12,6 +13,7 @@ export default class JsonqlStoreService { protected logger: any; constructor(logger: any) { + super(logger) // hack this.logger = typeof logger === 'function' ? logger : () => {}; // should this be WeakMap or should they be Map? @@ -36,7 +38,7 @@ export default class JsonqlStoreService { this.logger('$get', full, this.normalStore) if (store.has(evt)) { return this - .mapToArr(store.get(evt)) + .arrayFrom(store.get(evt)) .map( l => { if (full) { return l; @@ -83,14 +85,6 @@ export default class JsonqlStoreService { // protected / PROTECTED METHODS // ///////////////////////////////// - /** - * @param {any} mapObj the Map object - * @return {array} transform to array to work with - */ - protected mapToArr(mapObj: any): any[] { - return Array.from(mapObj) - } - /** * make sure we store the argument correctly * @param {*} arg could be array @@ -175,7 +169,7 @@ export default class JsonqlStoreService { * @return {boolean} true on exist */ protected checkContentExist(args: any[], fnSet: Map): boolean { - let list = this.mapToArr(fnSet) + let list = this.arrayFrom(fnSet) return !!list .filter((value: any, index: number, array: any[]): boolean => { let [hash,] = value; @@ -216,7 +210,7 @@ export default class JsonqlStoreService { let store = this.lazyStore.get(evtName) if (store) { this.logger('checkTypeInLazyStore', store) - return !!this.mapToArr(store) + return !!this.arrayFrom(store) .filter((value: any, index: number, array: any[]): boolean => { let [,,t] = value; return t !== type; diff --git a/packages/event/src/suspend.d.ts b/packages/event/src/suspend.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..1169f903b9cf50f0d82b2ffb722db4b106996144 --- /dev/null +++ b/packages/event/src/suspend.d.ts @@ -0,0 +1,16 @@ +export default class JsonqlSuspend { + protected queue: Set; + protected suspend?: any; + protected lastSuspendState?: any; + constructor(logger: any); + /** + * getter to get back the current suspend state + * @return {boolean} the suspend state + */ + readonly $suspend: boolean; + /** + * @param {any} mapObj the Map object + * @return {array} transform to array to work with + */ + protected arrayFrom(mapObj: any): any[]; +} diff --git a/packages/event/src/suspend.ts b/packages/event/src/suspend.ts new file mode 100644 index 0000000000000000000000000000000000000000..290244a265c2fee86db79bb12bc160299f77ddbd --- /dev/null +++ b/packages/event/src/suspend.ts @@ -0,0 +1,37 @@ +// the suspend ported from nb-event-service +// This is different from the nb-event-service +// instead of using object.defineProperty we just use the native ES6 setter +// with Typescript private + +export default class JsonqlSuspend { + protected queue: Set; + protected suspend?: any; // Typescript is a fucking joke + protected lastSuspendState?: any; // Typescript is a fucking joke + + constructor(logger: any) { + + this.lastSuspendState = null; + this.suspend = null; + this.queue = new Set() + } + + + + /** + * getter to get back the current suspend state + * @return {boolean} the suspend state + */ + public get $suspend(): boolean { + return this.suspend; + } + + /** + * @param {any} mapObj the Map object + * @return {array} transform to array to work with + */ + protected arrayFrom(mapObj: any): any[] { + return Array.from(mapObj) + } + + +} diff --git a/packages/event/tests/basic.test.js b/packages/event/tests/basic.test.js index 139c4e020e058714a5ba90c5f52cad040b4f9edb..fca5db4aaea1900f095bd5249b5dc1f94d7f71b4 100644 --- a/packages/event/tests/basic.test.js +++ b/packages/event/tests/basic.test.js @@ -1,14 +1,14 @@ const test = require('ava') // import the cjs version for testing -const { JsonqlEventService } = require('../dist/jsonql-event-service.cjs') +const JsonqlEvent = require('../dist/jsonql-event.cjs') const logger = require('debug')('nb-event-service') const debug = require('debug')('nb-event-service:test:basic') let value = 1000; -debug(JsonqlEventService) +debug(JsonqlEvent) test.before( t => { - t.context.evtSrv = new JsonqlEventService(logger) + t.context.evtSrv = new JsonqlEvent(logger) }) test('It should able to validate the evt', t => { diff --git a/packages/event/tests/fixtures/index.html b/packages/event/tests/fixtures/index.html index 1006f42d008ff620e27cc663fbb55d60e2d256fe..ec6323c9e404ba2d3d0966fbc2b1bfc83b6b1d54 100644 --- a/packages/event/tests/fixtures/index.html +++ b/packages/event/tests/fixtures/index.html @@ -8,10 +8,10 @@

Just look at the console log

- +