@wordpress/data
Version:
Data module for WordPress.
133 lines (131 loc) • 4.76 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// packages/data/src/redux-store/metadata/reducer.ts
var reducer_exports = {};
__export(reducer_exports, {
default: () => reducer_default
});
module.exports = __toCommonJS(reducer_exports);
var import_equivalent_key_map = __toESM(require("equivalent-key-map"));
var import_utils = require("./utils");
var subKeysIsResolved = (0, import_utils.onSubKey)("selectorName")((state = new import_equivalent_key_map.default(), action) => {
switch (action.type) {
case "START_RESOLUTION": {
const nextState = new import_equivalent_key_map.default(state);
nextState.set((0, import_utils.selectorArgsToStateKey)(action.args), {
status: "resolving"
});
return nextState;
}
case "FINISH_RESOLUTION": {
const nextState = new import_equivalent_key_map.default(state);
nextState.set((0, import_utils.selectorArgsToStateKey)(action.args), {
status: "finished"
});
return nextState;
}
case "FAIL_RESOLUTION": {
const nextState = new import_equivalent_key_map.default(state);
nextState.set((0, import_utils.selectorArgsToStateKey)(action.args), {
status: "error",
error: action.error
});
return nextState;
}
case "START_RESOLUTIONS": {
const nextState = new import_equivalent_key_map.default(state);
for (const resolutionArgs of action.args) {
nextState.set((0, import_utils.selectorArgsToStateKey)(resolutionArgs), {
status: "resolving"
});
}
return nextState;
}
case "FINISH_RESOLUTIONS": {
const nextState = new import_equivalent_key_map.default(state);
for (const resolutionArgs of action.args) {
nextState.set((0, import_utils.selectorArgsToStateKey)(resolutionArgs), {
status: "finished"
});
}
return nextState;
}
case "FAIL_RESOLUTIONS": {
const nextState = new import_equivalent_key_map.default(state);
action.args.forEach((resolutionArgs, idx) => {
const resolutionState = {
status: "error",
error: void 0
};
const error = action.errors[idx];
if (error) {
resolutionState.error = error;
}
nextState.set(
(0, import_utils.selectorArgsToStateKey)(resolutionArgs),
resolutionState
);
});
return nextState;
}
case "INVALIDATE_RESOLUTION": {
const nextState = new import_equivalent_key_map.default(state);
nextState.delete((0, import_utils.selectorArgsToStateKey)(action.args));
return nextState;
}
}
return state;
});
var isResolved = (state = {}, action) => {
switch (action.type) {
case "INVALIDATE_RESOLUTION_FOR_STORE":
return {};
case "INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR": {
if (action.selectorName in state) {
const {
[action.selectorName]: removedSelector,
...restState
} = state;
return restState;
}
return state;
}
case "START_RESOLUTION":
case "FINISH_RESOLUTION":
case "FAIL_RESOLUTION":
case "START_RESOLUTIONS":
case "FINISH_RESOLUTIONS":
case "FAIL_RESOLUTIONS":
case "INVALIDATE_RESOLUTION":
return subKeysIsResolved(state, action);
}
return state;
};
var reducer_default = isResolved;
//# sourceMappingURL=reducer.js.map