All files actions.ts

100% Statements 10/10
100% Branches 6/6
100% Functions 1/1
100% Lines 9/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33  2x 2x             2x 3x   3x 2x   3x 1x   3x                            
export const INVALIDATE_CACHE = "@@redux-cache/INVALIDATE_CACHE";
 
export interface InvalidateCacheAction {
	type: string,
	payload: {
		reducers: string[]
	}
}
 
/**
 * This action can be used to invalidate the cache for a given array of reducers.
 * 
 * @param {string[]} [reducersToInvalidate=[]] List of reducers to invalidate
 * @returns {InvalidateCacheAction}
 */
export const invalidateCache = (reducersToInvalidate: string[] | string = []): InvalidateCacheAction => {
	let reducers;
 
	if (reducersToInvalidate instanceof Array) {
		reducers = reducersToInvalidate;
	}
 
	if (typeof reducersToInvalidate === "string") {
		reducers = [reducersToInvalidate];
	}
 
	return {
		type: INVALIDATE_CACHE,
		payload: {
			reducers
		}
	}
}