UNPKG

@dnb/eufemia

Version:

DNB Eufemia Design System UI Library

21 lines 729 B
import pointer from '../../utils/json-pointer'; import { createSharedState } from '../../../../shared/helpers/useSharedState'; import structuredClone from '@ungap/structured-clone'; 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