UNPKG

electron-event-flux

Version:

Redux store which synchronizes between instances in multiple process

99 lines (98 loc) 3.76 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spread = (this && this.__spread) || function () { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; }; Object.defineProperty(exports, "__esModule", { value: true }); var MainStoreBase_1 = require("./MainStoreBase"); var StoreDeclarer_1 = require("./StoreDeclarer"); var WinPackStore = /** @class */ (function (_super) { __extends(WinPackStore, _super); function WinPackStore() { return _super !== null && _super.apply(this, arguments) || this; } WinPackStore.prototype.destroy = function () { (this.getSubStores() || []).map(function (store) { store.destroy && store.destroy(); }); }; return WinPackStore; }(MainStoreBase_1.default)); exports.WinPackStore = WinPackStore; var MultiWinManagerStore = /** @class */ (function (_super) { __extends(MultiWinManagerStore, _super); function MultiWinManagerStore() { var _this = _super.call(this) || this; _this.state = { clientIds: [] }; return _this; } MultiWinManagerStore.prototype.addWin = function (winId) { var clientIds = this.state.clientIds; if (clientIds.indexOf(winId) === -1) { this.setState({ clientIds: __spread(clientIds, [winId]) }); this.winPackMapStore.add(winId, function (store) { store.clientId = winId; }); this.emitter.emit('did-add-win', winId); } }; MultiWinManagerStore.prototype.deleteWin = function (winId) { var clientIds = this.state.clientIds; var index = clientIds.indexOf(winId); if (index !== -1) { this.setState({ clientIds: __spread(clientIds.slice(0, index), clientIds.slice(index + 1)) }); this.emitter.emit('did-remove-win', winId); } if (!this._appStore.willQuit) { this.winPackMapStore.get(winId).destroy(); } this.winPackMapStore.delete(winId); }; MultiWinManagerStore.prototype.getClienIds = function () { return this.state.clientIds; }; MultiWinManagerStore.prototype.onDidAddWin = function (callback) { return this.emitter.on('did-add-win', callback); }; MultiWinManagerStore.prototype.onDidRemoveWin = function (callback) { return this.emitter.on('did-remove-win', callback); }; return MultiWinManagerStore; }(MainStoreBase_1.default)); exports.default = MultiWinManagerStore; MultiWinManagerStore.innerStores = { winPackMap: StoreDeclarer_1.declareStoreMap(WinPackStore, { defaultFilter: true, storeDefaultFilter: true }) };