mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 15:06:20 +00:00
e1f5df6b1c
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.
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { useBetween } from 'use-between';
|
|
import { useWiredToolsStore } from './useWiredToolsStore';
|
|
|
|
/**
|
|
* Read-only slice of the Wired tools store: account preferences,
|
|
* room-settings flags, variable definitions / assignments, plus the
|
|
* two derived 'should show X button' booleans.
|
|
*
|
|
* Components that only need to render Wired state subscribe through
|
|
* this hook so it's easy to grep for read-only consumers vs. the
|
|
* imperative ones (which use useWiredToolsActions).
|
|
*/
|
|
export const useWiredToolsState = () =>
|
|
{
|
|
const {
|
|
accountPreferences,
|
|
roomSettings,
|
|
showInspectButton,
|
|
showToolbarButton,
|
|
userVariableDefinitions,
|
|
userVariableAssignments,
|
|
furniVariableDefinitions,
|
|
furniVariableAssignments,
|
|
roomVariableDefinitions,
|
|
roomVariableAssignments,
|
|
contextVariableDefinitions,
|
|
areUserVariablesLoaded
|
|
} = useBetween(useWiredToolsStore);
|
|
|
|
return {
|
|
accountPreferences,
|
|
roomSettings,
|
|
showInspectButton,
|
|
showToolbarButton,
|
|
userVariableDefinitions,
|
|
userVariableAssignments,
|
|
furniVariableDefinitions,
|
|
furniVariableAssignments,
|
|
roomVariableDefinitions,
|
|
roomVariableAssignments,
|
|
contextVariableDefinitions,
|
|
areUserVariablesLoaded
|
|
};
|
|
};
|