-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: utils for the mutation of states with config
- Loading branch information
1 parent
95e7285
commit d18e59b
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/x-components/src/store/utils/config-store.utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; | ||
} |