inversify-devtools
Version:
inversify-devtools
68 lines (67 loc) • 2.73 kB
JavaScript
;
var Immutable = require("immutable");
var action_types_1 = require("../constants/action_types");
var defaultState = Immutable.fromJS({
__inversifyDevtools__: null,
kernels: [],
windowHeight: window.innerHeight,
windowWidth: window.innerWidth
});
function initAppSuccess(previousState, action) {
return previousState.set("__inversifyDevtools__", action.__inversifyDevtools__);
}
function resize(previousState, action) {
return previousState.withMutations(function (ctx) {
ctx.set("windowWidth", action.width).set("windowHeight", action.height);
});
}
function kernelConnectSucess(previousState, action) {
var kernels = previousState.get("kernels");
var dictionary = action.kernel.details._bindingDictionary._dictionary;
dictionary.forEach(function (keyValPair) {
keyValPair.selected = false;
});
var updatedKernels = kernels.push(action.kernel);
return previousState.set("kernels", updatedKernels);
}
function selectKernel(previousState, action) {
var kernels = previousState.get("kernels");
var updatedKernels = kernels.map(function (kernel) {
kernel.selected = (kernel.details.guid === action.kernel.details.guid);
return kernel;
});
return previousState.set("kernels", updatedKernels);
}
function selectBinding(previousState, action) {
var kernels = previousState.get("kernels");
var updatedKernels = kernels.map(function (kernel) {
if (kernel.details.guid === action.kernelGuid) {
var dictionary = kernel.details._bindingDictionary._dictionary;
dictionary = dictionary.map(function (keyValPair) {
keyValPair.selected = (keyValPair.guid === action.keyVal.guid);
return keyValPair;
});
}
return kernel;
});
return previousState.set("kernels", updatedKernels);
}
var appReducer = function (previousState, action) {
if (previousState === void 0) { previousState = defaultState; }
switch (action.type) {
case action_types_1.default.RESIZE:
return resize(previousState, action);
case action_types_1.default.APP_INIT_SUCCESS:
return initAppSuccess(previousState, action);
case action_types_1.default.KERNEL_CONNECT_SUCCESS:
return kernelConnectSucess(previousState, action);
case action_types_1.default.SELECT_KERNEL:
return selectKernel(previousState, action);
case action_types_1.default.SELECT_BINDING:
return selectBinding(previousState, action);
default:
return previousState;
}
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = appReducer;