@dnb/eufemia
Version:
DNB Eufemia Design System UI Library
21 lines • 767 B
JavaScript
import pointer from "../../utils/json-pointer/index.js";
import { createSharedState } from "../../../../shared/helpers/useSharedState.js";
import { structuredClone } from "../../../../shared/helpers/structuredClone.js";
export default function setData(id, data) {
const sharedState = createSharedState(id);
if (data) {
sharedState.extend(data);
}
const update = (path, value = undefined) => {
const existingData = structuredClone(sharedState.data || {});
if (typeof value === 'function') {
value = value(pointer.has(existingData, path) ? pointer.get(existingData, path) : undefined);
}
pointer.set(existingData, path, value);
sharedState.extend(existingData);
};
return {
update
};
}
//# sourceMappingURL=setData.js.map