mattermost-redux
Version:
Common code (API client, Redux stores, logic, utility functions) for building a Mattermost client
44 lines (43 loc) • 1.49 kB
JavaScript
;
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
Object.defineProperty(exports, "__esModule", { value: true });
const redux_1 = require("redux");
const action_types_1 = require("mattermost-redux/action_types");
function jobs(state = {}, action) {
switch (action.type) {
case action_types_1.JobTypes.RECEIVED_JOB: {
const nextState = { ...state };
nextState[action.data.id] = action.data;
return nextState;
}
case action_types_1.JobTypes.RECEIVED_JOBS: {
const nextState = { ...state };
for (const job of action.data) {
nextState[job.id] = job;
}
return nextState;
}
default:
return state;
}
}
function jobsByTypeList(state = {}, action) {
switch (action.type) {
case action_types_1.JobTypes.RECEIVED_JOBS_BY_TYPE: {
const nextState = { ...state };
if (action.data && action.data.length && action.data.length > 0) {
nextState[action.data[0].type] = action.data;
}
return nextState;
}
default:
return state;
}
}
exports.default = (0, redux_1.combineReducers)({
// object where every key is the job id and has an object with the job details
jobs,
// object where every key is a job type and contains a list of jobs.
jobsByTypeList,
});