UNPKG

wxt-zustand

Version:

High-performance Zustand state management for WXT web extensions with seamless cross-tab synchronization and sub-10ms React re-renders

35 lines 1.16 kB
// Helpers to transform Zustand state for cross-context sync without losing actions /** * Returns a shallow copy of the given state with any function-valued * properties removed. This ensures we only send serializable data across * messaging/storage layers. */ export function stripFunctionProps(state) { if (state === null || typeof state !== 'object') return state; const src = state; const out = {}; for (const key of Object.keys(src)) { const val = src[key]; if (typeof val !== 'function') out[key] = val; } return out; } /** * Merge next state into a new object while preserving any function-valued * properties from the current state. Non-function keys are replaced exactly * by `next` to keep replace semantics for data. */ export function mergeStatePreservingFunctions(current, next) { const curr = current; const nxt = next; const merged = { ...nxt }; for (const key of Object.keys(curr)) { const val = curr[key]; if (typeof val === 'function') merged[key] = val; } return merged; } //# sourceMappingURL=stateTransforms.js.map