mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
Split useWiredTools into state + actions via useBetween singleton
useWiredTools backs 20 consumers with a 618-line wide state + actions surface; split it along the read/write seam so it's clear at the import site whether a view is rendering Wired data or mutating it. Because the actions need access to setters (setUserVariableAssignments, setFurniVariableAssignments, ...), this isn't the same pure-action shape as doorbell/friend-request. Used the useBetween singleton indirection instead: - useWiredToolsStore (internal) — the entire previous useWiredToolsState body, untouched. State + listeners + effects + actions in one closure. - useWiredToolsState (public, read-only) — useBetween(useWiredToolsStore) filtered to the 12 state fields (accountPreferences, roomSettings, showInspect/Toolbar booleans, variable definitions+assignments, areUserVariablesLoaded). - useWiredToolsActions (public, imperative) — same singleton filtered to the 13 actions (updateAccountPreferences, saveRoomSettings, requestUserVariables, assignXxx/removeXxx/updateXxx variable helpers, openMonitor / openInspectionForFurni / openInspectionForUser). - useWiredTools (deprecated shim) — composes both, preserves the full historical shape so the 20 existing consumers keep working. useBetween ensures all four entry points hit the same instance, so the state + dispatch loop stays a single source of truth. This is also the shape that a future migration to a Zustand slice would inherit cleanly — each public hook becomes a slice subscription.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { useBetween } from 'use-between';
|
||||
import { useWiredToolsStore } from './useWiredToolsStore';
|
||||
|
||||
/**
|
||||
* Imperative slice of the Wired tools store: state-mutating actions
|
||||
* (assignXxx / removeXxx / updateXxx) plus the link-event openers
|
||||
* (openMonitor / openInspectionForFurni / openInspectionForUser) and
|
||||
* the persistence helpers (saveRoomSettings, updateAccountPreferences,
|
||||
* requestUserVariables).
|
||||
*
|
||||
* Stays separate from useWiredToolsState so components that only need
|
||||
* to trigger Wired actions don't have to pull in the full state shape.
|
||||
*/
|
||||
export const useWiredToolsActions = () =>
|
||||
{
|
||||
const {
|
||||
updateAccountPreferences,
|
||||
saveRoomSettings,
|
||||
requestUserVariables,
|
||||
assignUserVariable,
|
||||
removeUserVariable,
|
||||
updateUserVariableValue,
|
||||
assignFurniVariable,
|
||||
removeFurniVariable,
|
||||
updateFurniVariableValue,
|
||||
updateRoomVariableValue,
|
||||
openMonitor,
|
||||
openInspectionForFurni,
|
||||
openInspectionForUser
|
||||
} = useBetween(useWiredToolsStore);
|
||||
|
||||
return {
|
||||
updateAccountPreferences,
|
||||
saveRoomSettings,
|
||||
requestUserVariables,
|
||||
assignUserVariable,
|
||||
removeUserVariable,
|
||||
updateUserVariableValue,
|
||||
assignFurniVariable,
|
||||
removeFurniVariable,
|
||||
updateFurniVariableValue,
|
||||
updateRoomVariableValue,
|
||||
openMonitor,
|
||||
openInspectionForFurni,
|
||||
openInspectionForUser
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user