diff --git a/docs/pages/webitel-ui/api/transformers/Readme.md b/docs/pages/webitel-ui/api/transformers/Readme.md index 8c0c2986e..fd86cc6d8 100644 --- a/docs/pages/webitel-ui/api/transformers/Readme.md +++ b/docs/pages/webitel-ui/api/transformers/Readme.md @@ -159,3 +159,29 @@ starToSearch('search')({ search: 'string' }); // => { search: 'string*' } starToSearch('search')({ search: 'string*' }); ``` + +## withContext + +You can pass withContext option to pass context into transformer function as a second argument. + +example: +```js +const context = { + value: '1' + // ... +} + +convert = () => { + return applyTransform({}, [ + transformSchema + ], { + withContext: context, + }) +} +``` + +How it passes context into transformer function: +```js +transformer(result, withContext) +``` +That give you option to work with node context into transformer. diff --git a/package.json b/package.json index 276deb420..5517c88bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@webitel/ui-sdk", - "version": "24.8.23", + "version": "24.8.24", "private": false, "scripts": { "dev": "vite", diff --git a/src/api/transformers/applyTransform.js b/src/api/transformers/applyTransform.js index e242c04d6..1faf8550d 100644 --- a/src/api/transformers/applyTransform.js +++ b/src/api/transformers/applyTransform.js @@ -1,6 +1,11 @@ -const applyTransform = (target, transformers, { debug = false } = {}) => { +const applyTransform = (target, transformers, { debug = false, withContext = null } = {}) => { return transformers.reduce((result, transformer, index) => { if (debug) console.info(`applyTransform debug on step ${index}`, result); + + if (withContext) { + return transformer(result, withContext); + } + return transformer(result); }, target); };