Skip to main content
Version: 3.x

makeCustomizableData

The `makeCustomizableData` function allows you to execute a series of transformations on an objet.

makeCustomizableData function

Params

NameTypeDescription
initialTransformsany[]Array of transform functions

Return

It returns a new object with the registerTransform and makeData functions:

TypeDescription
registerTransformA method to allow to register new transformations
makeDataApply all transformations to a variable

Example

import { makeCustomizableData } from "@front-commerce/core/graphql";

const transformer = (data) => {
// Do your transformation
return data;
};

const customData = makeCustomizableData([transformer]);

registerTransform

Add a transform function

Params

NameTypeDescription
transformfunctionThe transform function

Return

Nothing

Example

import { makeCustomizableData } from "@front-commerce/core/graphql";

const customData = makeCustomizableData();

const transformer = (data) => {
// Do your transformation
return data;
};

customData.registerTransform(transformer);

makeData

Apply all transformations to a variable

Params

NameTypeDescription
dataanyThe data to transform

Return

TypeDescription
anyThe transformed data

Example

import { makeCustomizableData } from "@front-commerce/core/graphql";

const data = {
id: 1,
name: "My product",
price: 100,
};
const customData = makeCustomizableData();
const customizedData = customData.makeData(data);

transform function

Params

NameTypeDescription
dataanyThe data to transform

Return

TypeDescription
anyThe transformed data

Example

function myTransformer(data) {
// Do your transformation
return data;
}