-
Notifications
You must be signed in to change notification settings - Fork 178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow specifying data transform via custom JS function #536
Comments
Actually, if all we care about is transforming root data before load & before save, this can be easily done with the current hook system (I've just added another hook to facilitate). E.g.: Mavo.hooks.add("render-start", function(env) {
if (this.id !== "myMavoApp") {
return;
}
// Transform env.data before rendering
env.data.foo = 1;
});
Mavo.hooks.add("getdata-end", function(env) {
if (this.id !== "myMavoApp") {
return;
}
// Undo env.data transformation before saving
delete env.data.foo;
}); So if this covers use cases, maybe this can be a documentation issue? Are there use cases for doing this on a node-by-node basis? |
@DmitrySharabin we should probably mention this somewhere in the docs, what do you think? |
Totally agree! I even bookmarked this issue to be able to re-use the code snippet you suggested when needed. 😅 What if we add a new subsection to the For JS developers section? How would we name it? What about Transforming root data before load and/or save? |
Sounds good, thank you so much! 🙏🏼 |
It’s my pleasure! Get ready for the PR. 😉 |
@LeaVerou Done! Please feel free to correct my wording. |
Idea inspired by @plehegar's markup-based system.
While we do generally try to avoid any need for custom JS, sometimes custom things are needed. We do have
mv-path
for simple property-chain transformations and property lookups, which has the benefit of being automatically reversible, but that doesn't cover all possible transformations, and even for good JS developers, it's kinda tricky right now to write a custom data transformation.We should allow the user to specify custom transformations (in/out), either in MavoScript or JS, and possibly even make the current ones a special case of those (though that would be backwards incompatible, but hey, we're still in v0.x.y).
The text was updated successfully, but these errors were encountered: