Skip to content

Latest commit

 

History

History
66 lines (49 loc) · 2.07 KB

File metadata and controls

66 lines (49 loc) · 2.07 KB

Migration Guide: 1.3.1

This release scopes action state to the active reader profile. It is a breaking change for any custom component that reads from or dispatches to state.actions.keys directly.


Breaking: actions.keys is now keyed by profile

The Redux actions.keys object was previously a flat map of action states shared across all reader types. It is now partitioned by reader profile ("epub", "webPub", "audio"), so each profile tracks its own action state independently.

Before (1.3.0)

// Reading state
const actionState = useAppSelector(
  state => state.actions.keys[ThActionsKeys.toc]
);

// Dispatching
dispatch(setActionOpen({ key: ThActionsKeys.toc, isOpen: true }));
dispatch(toggleActionOpen({ key: ThActionsKeys.toc }));

After (1.3.1)

// Reading state — go through the profile first
const profile = useAppSelector(state => state.reader.profile);
const actionState = useAppSelector(
  state => profile ? state.actions.keys[profile][ThActionsKeys.toc] : undefined
);

// Dispatching — include profile in every payload
if (profile) {
  dispatch(setActionOpen({ key: ThActionsKeys.toc, isOpen: true, profile }));
  dispatch(toggleActionOpen({ key: ThActionsKeys.toc, profile }));
}

Updated type signatures

ActionsReducerState.keys is now typed as ActionKeysState:

// Before
keys: {
  [key in ActionsStateKeys]?: ActionStateObject;
}

// After
interface ActionKeysState {
  [profile: string]: {
    [key in ActionsStateKeys]?: ActionStateObject;
  };
}

ActionStateOpenPayload and ActionStateTogglePayload both gained a required profile: string field.

Checklist for custom components

  • Replace state.actions.keys[myKey] with state.actions.keys[profile][myKey]
  • Add const profile = useAppSelector(state => state.reader.profile) where missing
  • Guard dispatches with if (profile) before calling setActionOpen / toggleActionOpen
  • Add profile to every setActionOpen / toggleActionOpen payload
  • Add profile to the useCallback dependency array for any setOpen callbacks