majg0 / nxtpression Goto Github PK
View Code? Open in Web Editor NEWObservable-based template expression library
Observable-based template expression library
Needs tokens, parsing, compilation and a test each
Add support for the {{ { property } }}
shorthand syntax
There is some already existing code which is supposed to handle grouping expressions with parentheses; add extensive tests for this and make sure they pass
My suggested syntax is
a | getRecord() if !isMatch() { discard() } else if isBad() { error() } else { process() } | logResult()
I.e. this would kinda compile to
let b = getRecord(a)
let c
if !isMatch(b) { c = discard(b) } else if isBad(b) { c = error(b) } else { c = process(b) }
logResult(c)
For this we need some new tokens;
I also introduce scopes via curly braces. For now these only have to be supported after if/else.
Needs new tokens, new parsing and new compilation code on top of tests
Rename setting to onUndefinedVariableAccess
and take representative string values instead in order to ensure extensibility.
throw
IGNORE
forward
Add tests for all relevant functions for throwing or not.
Update docs
Here's a silly example one would probably never write:
{{ nums | reduce((a, b) => add(a, b), 0) }}
because they would just use an add function capped at two arguments if they needed this capability.
Hold off on implementing until need arises.
// number
{{ 3.141562 }}
// string
{{ "hi" }}
{{ 'hi' }}
// property
{{ a.b }}
{{ a[b] }}
{{ [...arr, item] }}
{{ {...obj, key: value} }}
rxjs
into a peer dependencyGiven that nxtpressions are bound to exist in JSON and JavaScript strings, would be very good to also explore the possibilities of including this inside a JSON editor - whether actually A) an extension of the JSON version editor of Monaco's or B) a wholly new JSON editor - I don't know. But it would be badass, so we should definitely investigate.
A quick look indicates we should be able to use https://microsoft.github.io/monaco-editor/api/modules/monaco.languages.html#setmonarchtokensprovider ; That said, https://stackoverflow.com/a/47085671/8020381 so might need to go with option B.
Here's a way to achieve it microsoft/monaco-editor#252 (comment)
Approach A) Write a language syntax definition for the Monaco editor (used by VS Code among others). This can be accomplished using Monarch: https://microsoft.github.io/monaco-editor/monarch.html
Approach B) However, not sure we need this - since we can already tokenize ourselves, maybe it's easier to just parse strings to detect templates and traverse the ast to put the colors in the editor. Here's some more info and perhaps a good idea of debouncing microsoft/monaco-editor#851 (comment)
Probably favoring approach B
Should an object template be able to reference a path in itself?
For example:
{
a: '{{ 1 }}',
b: '{{ a }}'
} // => { a: 1, b: 1 }
Consider today’s
a | b() + 1
Or worse
a | (b() + 1) * (2 * 3) / (c - 4)
It’s far from obvious how to properly compile this. (How does b get its a arg? In what order does things evaluate?)
We should drop support for this.
Consider instead
a | b() | +(1) | *(2, 3) | /(c | -(4))
Or
a | b() | add(1) | mul(2, 3) | div(c | sub(4))
This is much cleaner and easy to follow as for understanding what happens. Also way easier to generate code for.
I’m thinking we should go for both +(1) and add(1) styles. For that I think we need to change how an identifier token is regexed, right now the + char isn’t there e.g.
Tasks;
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.