import type { RookSyncGateState, Action } from './RookSyncGateTypes'; /** * The rookSyncGateReducer function in TypeScript handles various actions to update the state of a * RookSyncGate component. * @param {RookSyncGateState} state - The `state` parameter in the `rookSyncGateReducer` function * represents the current state of the RookSyncGate module. It contains various properties such as * `ready`, `environment`, `clientUUID`, `password`, `userID`, and `permissions`. The reducer function * takes an action and * @param {Action} action - The `action` parameter in the `rookSyncGateReducer` function represents an * object that contains information about the action being dispatched. It typically has a `type` * property that indicates the type of action being performed, along with any additional data needed to * update the state. The reducer function uses this * @returns The reducer function `rookSyncGateReducer` returns a new state object based on the action * type provided. The state object is updated with the corresponding values based on the action type. * If the action type is not recognized, it returns the current state unchanged. */ export const rookSyncGateReducer = ( state: RookSyncGateState, action: Action ): RookSyncGateState => { switch (action.type) { case 'SET_READY': return { ...state, ready: action.ready }; case 'SET_ROOK_ENVIRONMENT': return { ...state, environment: action.environment }; case 'SET_CLIENT_UUID': return { ...state, clientUUID: action.clientUUID }; case 'SET_SECRET': return { ...state, secret: action.secret }; case 'SET_BUNDLE_ID': return { ...state, bundleId: action.bundle }; case 'SET_PACKAGE_NAME': return { ...state, packageName: action.package }; case 'SET_USER_ID': return { ...state, userID: action.userID }; case 'SET_ENABLE_LOGS': return { ...state, enableLogs: action.enableLogs }; case 'SET_PERMISSIONS': return { ...state, permissions: state.permissions + 1, }; default: return state; } };