-
Notifications
You must be signed in to change notification settings - Fork 8
feat(core): expressive content replacement#139
Conversation
🦋 Changeset detectedLatest commit: aee0091 The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@davidfurlong
davidfurlong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like using existing standards for this.
however I'm a bit hesitant of this exact implementation, as
- mustache hasn't had a commit in a year
- I'm concerned about how many functions will be needed to support all the edge cases
however I think it'll be reasonably easy to change later so I'm ok with going with it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overriding globals is probably not a good idea given that this code is executed in the same context as other apps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with this pattern, this list of functions is going to grow very long and it'll be bundled into every app.
stephancill
commented
Jan 2, 2024
I agree with your evaluation. Another gripe I have with mustache is that the syntax is quite verbose. The ideal library for our use case is lightweight and has a comprehensive library of helper built-in helper functions.
handlebars is an alternative based on mustache which is actively maintained but is a bit heavier (73kb) and contains a lot of logic that we won't be using and still lacks the comprehensive standard library.
A possible course of action could be to go ahead with mustache, take inspiration from existing other long-standing analogs like the python's jinja and implement their helper standard functions to start off with, bundle them all together for now and figure out a more sophisticated bundling solution in the long run.
I think this is a necessary feature if we want to make rich client-only logic possible - but not strictly necessary if we work under the assumption that every mod will have a backend which can handle this kind of transformation logic.
Uh oh!
There was an error while loading. Please reload this page.
Change Summary
This PR proposes a standard syntax for string manipulation inside Mod elements by adopting mustache.js. This library is lightweight at 6.5kb minified or 2.7kb minified+gzipped (bundlephobia) and uses a familiar
{{}}syntax for replacement as well aspath.to.valuesyntax for accessing nested context values, making it backwards compatible.Arbitrary functions can be exposed to the mustache syntax in the
replaceInlineContextfunction by passing anonymous function builders along with the context to the rendering function (see theLambdassection in the manual and spec).An example adjustment to the
replaceInlineContextfunction which introduces adecimalsoperator which displays a number to a fixed number of decimals would look like this:And would be used like this:
Merge Checklist