Download wp-calypso/client/state/country-states/reducer.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.34 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/country-states/reducer.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/state/country-states/reducer.js
-
curl -L -o reducer.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/country-states/reducer.js
1.34 kB
| import { withStorageKey } from '@automattic/state-utils'; | |
| import { | |
| COUNTRY_STATES_RECEIVE, | |
| COUNTRY_STATES_REQUEST, | |
| COUNTRY_STATES_REQUEST_FAILURE, | |
| COUNTRY_STATES_REQUEST_SUCCESS, | |
| } from 'calypso/state/action-types'; | |
| import { combineReducers, withSchemaValidation } from 'calypso/state/utils'; | |
| import { itemSchema } from './schema'; | |
| // Stores the complete list of states, indexed by locale key | |
| export const items = withSchemaValidation( itemSchema, ( state = {}, action ) => { | |
| switch ( action.type ) { | |
| case COUNTRY_STATES_RECEIVE: | |
| return { | |
| ...state, | |
| [ action.countryCode ]: action.countryStates, | |
| }; | |
| } | |
| return state; | |
| } ); | |
| // Tracks states list fetching state | |
| export const isFetching = ( state = {}, action ) => { | |
| switch ( action.type ) { | |
| case COUNTRY_STATES_REQUEST: { | |
| const { countryCode } = action; | |
| return { | |
| ...state, | |
| [ countryCode ]: true, | |
| }; | |
| } | |
| case COUNTRY_STATES_REQUEST_SUCCESS: { | |
| const { countryCode } = action; | |
| return { | |
| ...state, | |
| [ countryCode ]: false, | |
| }; | |
| } | |
| case COUNTRY_STATES_REQUEST_FAILURE: { | |
| const { countryCode } = action; | |
| return { | |
| ...state, | |
| [ countryCode ]: false, | |
| }; | |
| } | |
| } | |
| return state; | |
| }; | |
| const combinedReducer = combineReducers( { | |
| isFetching, | |
| items, | |
| } ); | |
| export default withStorageKey( 'countryStates', combinedReducer ); | |