From d18e59b4a4cbae13bbf0a11849d0d33e3c2aacef Mon Sep 17 00:00:00 2001 From: Guillermo Date: Wed, 4 Oct 2023 12:23:09 +0200 Subject: [PATCH] feat: utils for the mutation of states with config EMP-2327 --- .../src/store/utils/config-store.utils.ts | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 packages/x-components/src/store/utils/config-store.utils.ts 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 000000000..fdde8e410 --- /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 + }; +}