mikeric / rivets

Lightweight and powerful data binding.
http://rivetsjs.com
MIT License
3.23k stars 309 forks source link

Possibility to extend rivets expression syntax #591

Open stalniy opened 8 years ago

stalniy commented 8 years ago

Currently only keypath expressions and primitives can be passed as parameters to both components' attributes and binders value. I suggest to allow users to extend this functionality. So, I for example want to pass an object to binder:

<div rv-popover="enabled: user.isActive, template: customTemplate">{ user.name }</div>

Proposal:

That will allow devs to extend existing expressions with own a bit more advanced as I showed in popover example or even substitute parser with its own (or custom) implementation.

rivets.configure({ parser: new MyCustomParser() });

// or 
rivets.parser.addExpressionSupport(new ObjectExpressionParser());
stalniy commented 8 years ago

CC: @blikblum @Duder-onomy @Leeds-eBooks @mikeric @jccazeaux

stalniy commented 8 years ago

Please pay attention that I do not propose to add custom expression parsers in rivets-core but instead I propose to create extensibility point. So, people who wants to use more complex expression can do that

jccazeaux commented 8 years ago

Will a new (or extension of) parser be enough? If the parser decides it's an object, the binding mecanism will have have to know how to handle an object. Currently binding can only handle primitives and keypath types. Is it really possible with only an extension point ?

stalniy commented 8 years ago

@jccazeaux

yes, it's possible. So, look at the definition rv-popover="enabled: user.isActive, template: myTemplate". We want to subscribe to values of the object declaration and compute a new object each time any of its values are changed. And values are basically keypaths or primitives which rivets are able to parse

jccazeaux commented 8 years ago

@stalniy I read again your proposal, I didn't understand it well, it's clear now :wink: I like your example, handling objects could be usefull and not so hard to do. Is it really necessary to open an extension point ?