UNPKG

eventric-remote-inmemory

Version:
221 lines (172 loc) 6.33 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(); else if(typeof define === 'function' && define.amd) define(factory); else if(typeof exports === 'object') exports["eventric-remote-inmemory"] = factory(); else root["eventric-remote-inmemory"] = factory(); })(this, function() { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { module.exports = { endpoint: __webpack_require__(1), client: __webpack_require__(3) }; /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { var InMemoryRemoteEndpoint, pubSub, slice = [].slice; pubSub = __webpack_require__(2); InMemoryRemoteEndpoint = (function() { function InMemoryRemoteEndpoint() {} InMemoryRemoteEndpoint.prototype.setRPCHandler = function(handleRPCRequest) { this.handleRPCRequest = handleRPCRequest; }; InMemoryRemoteEndpoint.prototype.publish = function() { var aggregateId, arg, contextName, domainEventName, fullEventName, i, payload; contextName = arguments[0], arg = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), payload = arguments[i++]; domainEventName = arg[0], aggregateId = arg[1]; fullEventName = pubSub.getFullEventName(contextName, domainEventName, aggregateId); return pubSub.publish(fullEventName, payload); }; return InMemoryRemoteEndpoint; })(); module.exports = new InMemoryRemoteEndpoint; /***/ }, /* 2 */ /***/ function(module, exports) { var PubSub, slice = [].slice; PubSub = (function() { function PubSub() { this._subscribers = []; this._subscriberId = 0; } PubSub.prototype.subscribe = function(eventName, subscriberFunction) { return new Promise((function(_this) { return function(resolve) { var subscriber; subscriber = { eventName: eventName, subscriberFunction: subscriberFunction, subscriberId: _this._getNextSubscriberId() }; _this._subscribers.push(subscriber); return resolve(subscriber.subscriberId); }; })(this)); }; PubSub.prototype.publish = function(eventName, payload) { var subscribers; subscribers = this._getRelevantSubscribers(eventName); return Promise.all(subscribers.map(function(subscriber) { return subscriber.subscriberFunction(payload); })); }; PubSub.prototype._getRelevantSubscribers = function(eventName) { if (eventName) { return this._subscribers.filter(function(subscriber) { return subscriber.eventName === eventName; }); } else { return this._subscribers; } }; PubSub.prototype.unsubscribe = function(subscriberId) { return new Promise((function(_this) { return function(resolve) { _this._subscribers = _this._subscribers.filter(function(subscriber) { return subscriber.subscriberId !== subscriberId; }); return resolve(); }; })(this)); }; PubSub.prototype._getNextSubscriberId = function() { return this._subscriberId++; }; PubSub.prototype.getFullEventName = function() { var eventParts; eventParts = 1 <= arguments.length ? slice.call(arguments, 0) : []; eventParts = eventParts.filter(function(eventPart) { return eventPart != null; }); return eventParts.join('/'); }; return PubSub; })(); module.exports = new PubSub; /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { var InMemoryRemoteClient, endpoint, pubSub, slice = [].slice; endpoint = __webpack_require__(1); pubSub = __webpack_require__(2); InMemoryRemoteClient = (function() { function InMemoryRemoteClient() {} InMemoryRemoteClient.prototype.rpc = function(rpcRequest) { return new Promise((function(_this) { return function(resolve, reject) { return endpoint.handleRPCRequest(rpcRequest, function(error, result) { if (error) { return reject(error); } else { return resolve(result); } }); }; })(this)); }; InMemoryRemoteClient.prototype.subscribe = function() { var aggregateId, arg, contextName, domainEventName, fullEventName, handlerFunction, i; contextName = arguments[0], arg = 3 <= arguments.length ? slice.call(arguments, 1, i = arguments.length - 1) : (i = 1, []), handlerFunction = arguments[i++]; domainEventName = arg[0], aggregateId = arg[1]; fullEventName = pubSub.getFullEventName(contextName, domainEventName, aggregateId); return pubSub.subscribe(fullEventName, handlerFunction); }; InMemoryRemoteClient.prototype.unsubscribe = function(subscriberId) { return pubSub.unsubscribe(subscriberId); }; return InMemoryRemoteClient; })(); module.exports = new InMemoryRemoteClient; /***/ } /******/ ]) }); ;