Skip to content

Commit

Permalink
feat: utils for the mutation of states with config
Browse files Browse the repository at this point in the history
  • Loading branch information
CachedaCodes committed Oct 4, 2023
1 parent 95e7285 commit d18e59b
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/x-components/src/store/utils/config-store.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Config mutations, containing a method to change the current config and other to merge
* a new one.
*
* @public
*/
export interface ConfigMutations<T extends { config: T['config'] }> {
/**
* Sets the module config.
*
* @param config - The new config.
*/
setConfig(config: T['config']): void;
/**
* Merges a new config with the current one.
*
* @param config - The config to be merged.
*/
mergeConfig(config: T['config']): void;
}

/**
* Sets the request config. Can be used as a mutation.
*
* @param state - The {@link https://vuex.vuejs.org/guide/state.html | state} provided by Vuex.
* @param config - The new config.
*
* @public
*/
export function setConfig<T extends { config: T['config'] }>(state: T, config: T['config']): void {
state.config = config;
}

/**
* Merges a new config with the current one. Can be used as a mutation.
*
* @param state - The {@link https://vuex.vuejs.org/guide/state.html | state} provided by Vuex.
* @param config - The config to be merged.
*
* @public
*/
export function mergeConfig<T extends { config: T['config'] }>(
state: T,
config: Partial<T['config']>
): void {
state.config = {
...state.config,
...config
};
}

0 comments on commit d18e59b

Please sign in to comment.