UNPKG

@zubridge/electron

Version:

A streamlined state management library for Electron applications using Zustand.

27 lines (26 loc) 895 B
/** * Removes functions and non-serializable objects from a state object * to prevent IPC serialization errors when sending between processes * * @param state The state object to sanitize * @returns A new state object with functions and non-serializable parts removed */ export const sanitizeState = (state) => { if (!state || typeof state !== 'object') return state; const safeState = {}; for (const key in state) { const value = state[key]; // Skip functions which cannot be cloned over IPC if (typeof value !== 'function') { if (value && typeof value === 'object' && !Array.isArray(value)) { // Recursively sanitize nested objects safeState[key] = sanitizeState(value); } else { safeState[key] = value; } } } return safeState; };