UNPKG

gluebert

Version:

gluebert.js is a tiny helper orchestrating interactive html elements with on demand dynamic import Edit

1 lines 1.92 kB
'use strict';Object.defineProperty(exports,'__esModule',{value:!0});var _typeof='function'==typeof Symbol&&'symbol'==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&'function'==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?'symbol':typeof a},_createClass=function(){function a(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,'value'in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError('Cannot call a class as a function')}var MessageDispatcher=function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;_classCallCheck(this,a),this._actionAllocator=b,this._filter=null}return _createClass(a,[{key:'getMessageActionAllocatorType',value:function getMessageActionAllocatorType(a){return this._actionAllocator&&'object'===_typeof(this._actionAllocator)?_typeof(this._actionAllocator[a]):null}},{key:'validateMessageOnCustomFilter',value:function validateMessageOnCustomFilter(a){return'function'==typeof this._filter&&!this._filter(a)}},{key:'executeAction',value:function executeAction(a,b,c){switch(a){case'function':return this._actionAllocator[b](c);case'object':return this._runObjectAllocator(this._actionAllocator[b],c);default:}}},{key:'onMessage',value:function onMessage(a){if(!a)return!1;var b=a.getAction(),c=this.getMessageActionAllocatorType(b),d=a.getData();return!c||this.validateMessageOnCustomFilter(d)?!1:this.executeAction(c,b,a.getData())}},{key:'_runObjectAllocator',value:function _runObjectAllocator(a,b){var c='function'==typeof a.fn,d='function'==typeof a.filter;return c&&(!d||a.filter(b))?a.fn(b):null}},{key:'filter',value:function filter(a){return this._filter='function'==typeof a?a:null,this}}]),a}();exports.MessageDispatcher=MessageDispatcher;