How to use the @wordpress/data.combineReducers function in @wordpress/data

To help you get started, we’ve selected a few @wordpress/data examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yoast / wordpress-seo / js / src / edit.js View on Github external
_registerStoreInGutenberg() {
		return registerStore( "yoast-seo/editor", {
			reducer: combineReducers( reducers ),
			selectors,
			actions: pickBy( actions, x => typeof x === "function" ),
		} );
	}
github Automattic / wp-calypso / packages / data-stores / src / verticals / reducer.ts View on Github external
* Internal dependencies
 */
import { ActionType, Vertical } from './types';
import * as Actions from './actions';

const verticals: Reducer< Vertical[], ReturnType< typeof Actions[ 'receiveVerticals' ] > > = (
	state = [],
	action
) => {
	if ( action.type === ActionType.RECEIVE_VERTICALS ) {
		return action.verticals;
	}
	return state;
};

const reducer = combineReducers( { verticals } );

export type State = ReturnType< typeof reducer >;

export default reducer;
github WordPress / gutenberg / packages / core-data / src / reducer.js View on Github external
entitiesDataReducer = combineReducers( Object.entries( entitiesByKind ).reduce( ( memo, [ kind, subEntities ] ) => {
			const kindReducer = combineReducers( subEntities.reduce(
				( kindMemo, entityConfig ) => ( {
					...kindMemo,
					[ entityConfig.name ]: entity( entityConfig ),
				} ),
				{}
			) );

			memo[ kind ] = kindReducer;
			return memo;
		}, {} ) );
	}
github Automattic / WP-Job-Manager / assets / blocks / data / reducer.js View on Github external
/**
 * WordPress dependencies
 */
import { combineReducers } from '@wordpress/data';

/**
 * Internal dependencies
 */
import { UPDATE_JOB_LISTINGS, UPDATE_JOB_TYPES } from './action-types';

const jobListings = combineReducers( {
	items: ( state = [], action ) => action.type === UPDATE_JOB_LISTINGS ? action.listings : state,
} );

const jobTypes = combineReducers( {
	items: ( state = [], action ) => action.type === UPDATE_JOB_TYPES ? action.types : state,
} );

export default combineReducers( {
	jobListings,
	jobTypes,
} );
github WordPress / gutenberg / nux / store / reducer.js View on Github external
export function dismissedTips( state = {}, action ) {
	switch ( action.type ) {
		case 'DISMISS_TIP':
			return {
				...state,
				[ action.id ]: true,
			};

		case 'ENABLE_TIPS':
			return {};
	}

	return state;
}

const preferences = combineReducers( { areTipsEnabled, dismissedTips } );

export default combineReducers( { guides, preferences } );
github Automattic / wp-calypso / packages / data-stores / src / domain-suggestions / reducer.ts View on Github external
import { stringifyDomainQueryObject } from './utils';

const domainSuggestions: Reducer<
	Record< string, DomainSuggestion[] | undefined >,
	ReturnType< typeof Actions[ 'receiveDomainSuggestions' ] >
> = ( state = {}, action ) => {
	if ( action.type === ActionType.RECEIVE_DOMAIN_SUGGESTIONS ) {
		return {
			...state,
			[ stringifyDomainQueryObject( action.queryObject ) ]: action.suggestions,
		};
	}
	return state;
};

const reducer = combineReducers( { domainSuggestions } );

export type State = ReturnType< typeof reducer >;

export default reducer;
github Automattic / wp-calypso / packages / data-stores / src / verticals-templates / reducer.ts View on Github external
import * as Actions from './actions';

const templates: Reducer<
	Record< string, Template[] | undefined >,
	ReturnType< typeof Actions[ 'receiveTemplates' ] >
> = ( state = {}, action ) => {
	if ( action.type === ActionType.RECEIVE_TEMPLATES ) {
		return {
			...state,
			[ action.verticalId ]: action.templates,
		};
	}
	return state;
};

const reducer = combineReducers( { templates } );

export type State = ReturnType< typeof reducer >;

export default reducer;
github Automattic / wp-calypso / client / landing / gutenboarding / store / reducer.ts View on Github external
return action.verticals;
	}
	return state;
};

const siteVertical: Reducer<
	FormValue< SiteVertical >,
	ReturnType< typeof Actions[ 'setSiteVertical' ] >
> = ( state = EMPTY_FORM_VALUE, action ) => {
	if ( action.type === ActionType.SET_SITE_VERTICAL ) {
		return action.siteVertical;
	}
	return state;
};

const reducer = combineReducers( { siteType, siteTitle, verticals, siteVertical } );

export type State = ReturnType< typeof reducer >;

export default reducer;
github WordPress / gutenberg / packages / nux / src / store / reducer.js View on Github external
export function dismissedTips( state = {}, action ) {
	switch ( action.type ) {
		case 'DISMISS_TIP':
			return {
				...state,
				[ action.id ]: true,
			};

		case 'ENABLE_TIPS':
			return {};
	}

	return state;
}

const preferences = combineReducers( { areTipsEnabled, dismissedTips } );

export default combineReducers( { guides, tipInstanceIds, preferences } );
github WordPress / gutenberg / packages / editor / src / store / reducer.js View on Github external
*
 * @return {Object} Updated state.
 */
export function editorSettings( state = EDITOR_SETTINGS_DEFAULTS, action ) {
	switch ( action.type ) {
		case 'UPDATE_EDITOR_SETTINGS':
			return {
				...state,
				...action.settings,
			};
	}

	return state;
}

export default optimist( combineReducers( {
	postId,
	postType,
	preferences,
	saving,
	postLock,
	reusableBlocks,
	template,
	postSavingLock,
	isReady,
	editorSettings,
	postAutosavingLock,
} ) );