Transformation Functions
When storing values in data structures like array, Map, Set or object we may want to create a markup (Brackethtml) and add it to the template, for that we can use transform functions that inject a property (using Symbol) into the data structure and tells Bemtv to transform the data structure only when used in the template.
To create a transformation function we use the tFn()
function, it receives as its first argument a function that transforms the data structure and returns another function that involves the function passed as an argument:
To use the function just pass a list and it will return the same list with a Symbol injected:
Whenever this list is changed (eg $.list.push(item)
), Bemtv will detect and use the transform function again and rederize the change.
The transform functions can be incredibly powerful because with Brackethtml we can even return the markup with CSS-In-JS, so we can focus on the data structure.
Built-in transformation functions
Whenever you create a transformation function it is good practice to export the normal function that does the transform immediately:
Last updated