-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Refactor binding regex to small scanner to allow custom expressions to be defined #4080
Comments
How do you plan on building library? I have been string tenplating and binding a month or so and have been looping patterns in get sets The strings allow the on the fly But in the last two days I have been experimenting with placing the event handler in a property "touchDom" And then chaining other gets and sets on same pattern and for same usage as ternary without the "bind every time" issue I saw the possibility late in a long sleepless code cycle, Inawake testing have not had time/define properties on my Mac has been janky with this in descriptors To see if it will work But in theory it should be a better approach Gets sets plus returns of template strings then amalgammated in master prototype object In theory Would offer modular Dom and value binding omni directionally build the Dom and be repetitive and simple. As we both know, however, we don't live in theory. You're welcome to any of my work And am willing to do grunt work that aligns in purpose Let me know I"lol pass some pvt Pens so you can see what I am up to
|
This is something that could be handled by #3369 |
Previous related issues
At the moment all bindings are parsed using a regex. A frequent request for 1.0 is expansion of other expressions:
There was a previous effort to extract a separate library for expression at https://github.com/Polymer/polymer-expressions/tree/2.0-preview
How not to bloat the library
The general argument for not including this expressions is: it bloats the library. I completely agree with this statement. Therefore to provide flexibility for parsing the bindings, it would be nice to find a solution that 1. does not add bloat, but 2. is customizable to the users need. With the ability to define your own base class in Polymer 2.0, custom bindings could be a lot easier.
Proposed solution
To make this work, I did some hacking but got stuck quite fast. The main issue is that the regex is at the moment very limiting and you can't easily override/extend/modify this regex on runtime. All functions in the annotations file are static and have no instance attached.
Therefore it would be nice to replace the regex with a very simple scanner that verifies that a binding exists (e.g. between
{{}}
or[[]]
). Then it will extract everything between the bindings and pass these values on. The values are pre-processed when the constructor of the custom element is run, which invokes a static method calledprocessBindingValue
. The default implementation ofPolymer.Element
uses parts of the original regex to parse strings, numbers, variables and function calls.Now the benefit of this approach is that users can override the method and supply their custom parsing. Since ES6 classes are used,
super.processBindingValue
can be invoked to fallback to the implementation defined inPolymer.Element
. Users can then also mix in multiple behaviors with their own binding parsers to compose multiple expressions at once.Benefits of this approach
Since ES6 classes are used, the user can really easily override the base method defined in
Polymer.Element
. Most of the users won't and therefore there should not be any performance degradation. Users can opt-in, but have fully control on how they want to parse the bindings.CC @sorvell this issue was a result of our discussion at the Polymer summit last monday.
The text was updated successfully, but these errors were encountered: