Comments (9)
Doing this allow us to enable the following:
<div>${(firstName | capitalize) + " " + lastName}</div>
Basically when everything flows though, it's easy to have nested value converter, Binding behavior should still happen per binding
from aurelia.
Yep it does. We can also have nested Binding behavior. It's the same binding that flows through the bind calls, and it's the binding you modify
from aurelia.
@fkleuver binding behavior is supposed to modify binding, so it makes sense to have per binding and perhaps not possible to make it per expression, that's what I thought. Maybe you saw some direction for improvement?
from aurelia.
Additional possibilities for the binding behavior is one of the main reasons I raised this issue in the first place.
A rough idea I had is to have the AST expose a lightweight configuration API that allows you to set/unset flags on specific expressions.
Those flags can either be stored in an expression map per bound scope or per binding (I'd need to experiment with what works and what the perf implications are)
This would be useful for applying binding behaviors to only a certain part of an expression, e.g. foo.bind="(bar & oneTime) + baz"
(baz
is connected but bar
is not) but it would also open up the possibility of modifying the behavior of an expression by cloning it for a particular binding and then monkey patching the connect
, assign
or evaluate
method. For instance to enable two-way binding on expressions that normally don't allow it such as unary/binary/ternary. If the consumer knows how the target value needs to be reverse-evaluated, then it can be two-way bound.
I don't know yet if all of this would make sense and we'd need to take a close look at whether it's all worth the trouble. Too early to say anything without any experimentation
from aurelia.
It would be nice if there was a better API for binding behaviors other than monkey patching methods. The current way of writing them feels hacky and prone to error. It's not a hard requirement to improve this, but it would be very nice I think.
from aurelia.
Agreed. I'm thinking something among the lines of this:
IBinding {
applyBehavior(behavior: IBindingBehavior): IBinding;
}
IBindingBehavior {
updateTarget?(binding: IBinding, value: any): void;
updateSource?(binding: IBinding, value: any): void;
handleChange?(binding: IBinding, newValue: any, oldValue: any): void;
$bind?(binding: IBinding, flags: BindingFlags, scope: IScope): void;
// etc
}
export class Binding {
public updateTarget(value: any): void {
// more optimized/intelligent of course, a bit similar to subscriberCollection
if (this._behavior1) {
this._behavior1.updateTarget(this._behavior0, value);
} else if (this._behavior0) {
this._behavior0.updateTarget(this, value);
}
}
}
export class SomeFooBindingBehavior implements IBindingBehavior {
public updateTarget(binding: IBinding, value: any): void {
// some magic
if (value === undefined) value = null;
binding.updateTarget(value);
}
}
And of course the normal $bind
method if you need to just set the mode or do funny stuff like rebasing an expression (thinking of a better API for that too)
from aurelia.
It would be good to get some feedback from @zewa666 on this since he built some custom behaviors for the i18n plugin that we want to port to vnext.
from aurelia.
This sounds pretty nice. BindingBehaviors currently feel a bit hacky so everything we do here for cleaning up the API is a big win. The config part that @fkleuver mentioned could be useful for certain i18n use-cases
from aurelia.
Will not do this, the performance impact is too much actually.
from aurelia.
Related Issues (20)
- 🏁 Roadmap & Iteration plan Q1 2024 HOT 3
- flickering caused by aurelia rendering content before clearing the old HOT 2
- [RFC] Custom element bindables take priority over custom attribute
- [refactor] remove define life cycle HOT 1
- Vite plugin for aurelia 1.x? HOT 4
- Router load attribute: broken when using id & parameters.bind HOT 7
- Injecting IHttpClient error after beta 11 update
- Router swallows DI errors HOT 7
- Restrict behavior of custom attribute single value binding and primary bindable HOT 8
- Tweak aurelia package reexports HOT 9
- Validation Package - Email validation HOT 7
- Replacing view factory containers
- Vite load issue. HOT 2
- Define `ts-jest` config under `globals` is deprecated HOT 2
- 2.0.0-beta.15 - using @inject is throwing errors HOT 3
- CSS modules support for Vite HOT 6
- [DEV:aurelia] Error: AUR0153: Element has already been registered HOT 8
- Variables getting removed from production bundle HOT 11
- [RFC] synchronous vs asynchronous binding system for Aurelia 2 HOT 5
- 2.0.0-beta.12 - Custom elements instances are now different HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aurelia.