diff --git a/packages/x-components/src/store/utils/config-store.utils.ts b/packages/x-components/src/store/utils/config-store.utils.ts new file mode 100644 index 0000000000..fdde8e4105 --- /dev/null +++ b/packages/x-components/src/store/utils/config-store.utils.ts @@ -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 { + /** + * 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(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( + state: T, + config: Partial +): void { + state.config = { + ...state.config, + ...config + }; +}