selectors.ts 742 B

1234567891011121314151617
  1. import { ActionRemote, ActionStateSetLocal, ActionStateSetRemote } from './actions';
  2. import { GlobalState } from './reducer/types';
  3. export const isMaster = (state: Pick<GlobalState, 'player' | 'myClientName'>): boolean =>
  4. state.player.master === state.myClientName;
  5. export const isFromOurselves = (
  6. state: Pick<GlobalState, 'myClientName'>,
  7. action: ActionRemote,
  8. ): boolean => state.myClientName === action.fromClient;
  9. export const willBeMaster = (
  10. state: Partial<GlobalState> & Pick<GlobalState, 'myClientName'>,
  11. action: ActionStateSetLocal | ActionStateSetRemote,
  12. ): boolean => state.myClientName === action.payload?.master;
  13. export const getSongId = (state: Pick<GlobalState, 'player'>): number | null => state.player.songId;