@wordpress/widget-dashboard
Version:
Stateless rendering engine for widget dashboards: the WidgetDashboard compound component and its grid-settings kit.
25 lines (24 loc) • 964 B
JavaScript
import { observableMap } from "@wordpress/compose";
// packages/widget-dashboard/src/utils/runtime-actions-map.ts
function createRuntimeActionsMap() {
return observableMap();
}
/**
* Replaces what one render of an instance declares; an empty list clears it.
*
* @param {RuntimeActionsMap} map The dashboard's map.
* @param {string} uuid The instance.
* @param {string} renderId The render declaring.
* @param {WidgetRuntimeAction[]} actions The actions it declares.
*/
function declareRuntimeActions(map, uuid, renderId, actions) {
const declared = map.get(uuid);
if (actions.length === 0 && !declared?.has(renderId)) return;
const next = new Map(declared);
if (actions.length > 0) next.set(renderId, actions);
else next.delete(renderId);
if (next.size > 0) map.set(uuid, next);
else map.delete(uuid);
}
export { createRuntimeActionsMap, declareRuntimeActions };
//# sourceMappingURL=runtime-actions-map.mjs.map