Download wp-calypso/client/state/ui/action-log/reducer.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/ui/action-log/reducer.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/state/ui/action-log/reducer.js
-
curl -L -o reducer.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/ui/action-log/reducer.js
1.37 kB
| import { get } from 'lodash'; | |
| import { GUIDED_TOUR_UPDATE, ROUTE_SET, SITE_SETTINGS_RECEIVE } from 'calypso/state/action-types'; | |
| import { THEMES_REQUEST_SUCCESS } from 'calypso/state/themes/action-types'; | |
| const relevantAnalyticsEvents = [ 'calypso_themeshowcase_theme_click' ]; | |
| const relevantTypes = { | |
| // to catch all actions of a type: | |
| // ACTION_TYPE, | |
| // to catch actions of a type that match some criterion: | |
| // ACTION_TYPE: ( action ) => isValid( action.data ) | |
| GUIDED_TOUR_UPDATE, | |
| THEMES_REQUEST_SUCCESS, | |
| ROUTE_SET, | |
| SITE_SETTINGS_RECEIVE, | |
| }; | |
| const hasRelevantAnalytics = ( action ) => | |
| get( action, 'meta.analytics', [] ).some( ( record ) => | |
| relevantAnalyticsEvents.includes( record.payload.name ) | |
| ); | |
| const isRelevantActionType = ( action ) => | |
| relevantTypes.hasOwnProperty( action.type ) && | |
| ( typeof relevantTypes[ action.type ] !== 'function' || relevantTypes[ action.type ]( action ) ); | |
| const overSome = ( checks ) => ( item ) => checks.some( ( check ) => check( item ) ); | |
| const isRelevantAction = overSome( [ isRelevantActionType, hasRelevantAnalytics ] ); | |
| const newAction = ( action ) => ( { | |
| ...action, | |
| timestamp: Date.now(), | |
| } ); | |
| const maybeAdd = ( state, action ) => ( action ? [ ...state, action ].slice( -50 ) : state ); | |
| export default ( state = [], action ) => | |
| isRelevantAction( action ) ? maybeAdd( state, newAction( action ) ) : state; | |