Download wp-calypso/packages/data-stores/src/plans/reducer.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/plans/reducer.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/packages/data-stores/src/plans/reducer.ts
-
curl -L -o reducer.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/packages/data-stores/src/plans/reducer.ts
1.45 kB
| import { combineReducers } from '@wordpress/data'; | |
| import type { PlanAction } from './actions'; | |
| import type { Plan, PlanFeature, FeaturesByType, PlanProduct } from './types'; | |
| import type { Reducer } from 'redux'; | |
| // create a Locale type just for code readability | |
| type Locale = string; | |
| export const features: Reducer< Record< Locale, Record< string, PlanFeature > >, PlanAction > = ( | |
| state = {}, | |
| action | |
| ) => { | |
| switch ( action.type ) { | |
| case 'SET_FEATURES': | |
| return { ...state, [ action.locale ]: action.features }; | |
| default: | |
| return state; | |
| } | |
| }; | |
| export const featuresByType: Reducer< Record< Locale, Array< FeaturesByType > >, PlanAction > = ( | |
| state = {}, | |
| action | |
| ) => { | |
| switch ( action.type ) { | |
| case 'SET_FEATURES_BY_TYPE': | |
| return { ...state, [ action.locale ]: action.featuresByType }; | |
| default: | |
| return state; | |
| } | |
| }; | |
| export const plans: Reducer< Record< Locale, Plan[] >, PlanAction > = ( state = {}, action ) => { | |
| switch ( action.type ) { | |
| case 'SET_PLANS': | |
| return { ...state, [ action.locale ]: action.plans }; | |
| default: | |
| return state; | |
| } | |
| }; | |
| export const planProducts: Reducer< PlanProduct[], PlanAction > = ( state = [], action ) => { | |
| switch ( action.type ) { | |
| case 'SET_PLAN_PRODUCTS': | |
| return action.products; | |
| default: | |
| return state; | |
| } | |
| }; | |
| const reducer = combineReducers( { | |
| features, | |
| featuresByType, | |
| planProducts, | |
| plans, | |
| } ); | |
| export type State = ReturnType< typeof reducer >; | |
| export default reducer; | |