"use strict"; const xtend = require("xtend"); const nanoid = require("nanoid"); const immutable = require("immutable"); module.exports = function createWindowStore({onUpdated}) { let windows = immutable.OrderedMap([]); let activeWindow; let lastZIndex = 0; return { add: function (window_) { let id = nanoid(); windows = windows.set(id, xtend(window_, { id: id, x: window_.initialX, y: window_.initialY, width: window_.initialWidth, height: window_.initialHeight })); this.focus(id); /* NOTE: We let .focus call onUpdated. QUESTION: Is this not deduplicated by React? */ return id; }, focus: function (id) { let targetWindow = windows.get(id); windows.forEach((window_) => { window_.isActive = false; }); targetWindow.zIndex = lastZIndex++; targetWindow.isActive = true; activeWindow = targetWindow; onUpdated(); }, setPosition: function (id, x, y) { let targetWindow = windows.get(id); targetWindow.x = x; targetWindow.y = y; onUpdated(); }, setDimensions: function (id, width, height) { let targetWindow = windows.get(id); targetWindow.width = width; targetWindow.height = height; onUpdated(); }, close: function (id) { windows = windows.delete(id); onUpdated(); }, getAll: function () { return windows; }, getActiveWindow: function () { return activeWindow; } }; };