UNPKG

@stackend/api

Version:

JS bindings to api.stackend.com

72 lines 2.67 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CLEAR_BLOGS = exports.INVALIDATE_BLOGS = exports.RECEIVE_BLOGS = exports.REQUEST_BLOGS = void 0; // @flow var immutability_helper_1 = __importDefault(require("immutability-helper")); exports.REQUEST_BLOGS = 'REQUEST_BLOGS'; exports.RECEIVE_BLOGS = 'RECEIVE_BLOGS'; exports.INVALIDATE_BLOGS = 'INVALIDATE_BLOGS'; exports.CLEAR_BLOGS = 'CLEAR_BLOGS'; function blogs(state, action) { if (state === void 0) { state = { isFetching: false, didInvalidate: false, blogs: {}, idByPermalink: {}, auth: {}, lastUpdated: Date.now() }; } switch (action.type) { case exports.REQUEST_BLOGS: return (0, immutability_helper_1.default)(state, { isFetching: { $set: true }, didInvalidate: { $set: false } }); case exports.RECEIVE_BLOGS: { var newBlogs_1 = {}; var newIdByPermalink_1 = {}; action.entries.map(function (b) { newBlogs_1[b.id] = b; newIdByPermalink_1[b.permalink] = b.id; }); var newAuth_1 = {}; if (action.authBlogs) { action.authBlogs.map(function (ab) { return (newAuth_1[ab.id] = ab.auth); }); } if (action.authObjects) { Object.keys(action.authObjects).forEach(function (blogId) { var a = action.authObjects[blogId]; newAuth_1[blogId] = a; }); } return (0, immutability_helper_1.default)(state, { isFetching: { $set: false }, didInvalidate: { $set: false }, lastUpdated: { $set: Date.now() }, blogs: { $merge: newBlogs_1 }, idByPermalink: { $merge: newIdByPermalink_1 }, auth: { $merge: newAuth_1 } }); } case exports.INVALIDATE_BLOGS: return (0, immutability_helper_1.default)(state, { didInvalidate: { $set: true } }); case exports.CLEAR_BLOGS: return { isFetching: false, didInvalidate: false, blogs: {}, idByPermalink: {}, auth: {}, lastUpdated: Date.now() }; default: return state; } } exports.default = blogs; //# sourceMappingURL=blogReducer.js.map