Comments (8)
Thanks for the issue @ekzobrain , just to clarify: the current behavior is if theres no bindable defined, then we target the value
property on the custom attribute instances. Otherwise the primary bindable will be targeted in the single binding mode.
A bindable is considered primary if its one of the following:
- the only bindable, or
- the bindable with
primary: true
in is config, or - the first bindable when there is no primary defined
I think your case should work by default, or maybe can you provide a repro so its clearer whats missing?
from aurelia.
My major case is when I have a single bindable and don't want it to be assigned with attribute value (I don't want any bindable to be considered primary). But I have no way to do this now. And the overall approach seems too complicated and inconvinient. There are too many if/else in this logic :)
I suggest a simpler approach:
define primaryProperty
on customAttribute
definition, not on bindable. Then, by default, it would be value
, but may be changed to any other property name, or disabled completely with null
value (see my last two examples).
from aurelia.
This repro highlights my issue: https://stackblitz.com/edit/au2-conventions-u5ygqi?file=src%2Fsome-attribute.ts,src%2Fmy-app.ts,src%2Fmy-app.html
But it's just one of many similar cases, when bindable has data type other than string
, or some default value.
from aurelia.
@ekzobrain I think the idea of moving primary to the custom attribute definition sounds good, it's been quite an annoyance since primary
is on @bindable
but only custom attribute cares about it. We can make it backward compatible by checking whether primaryProperty
is defined or not.
If it's not defined (backward compat), then it'll automatically pick the one with the rules mentioned:
the only bindable, or
the bindable with primary: true in is config, or
the first bindable when there is no primary defined
If it's defined then it'll take over the process of defining primary bindable.
Thoughts @fkleuver @Sayan751 @jwx @brandonseydel @Vheissu ?
Though I think this is also related to a more general issue: what to do when the initial binding value is undefined
from the parent.
from aurelia.
I also like the idea of moving the primary bindable information to the custom attribute. That might take some burden off the bindable definition.
Though I think this is also related to a more general issue: what to do when the initial binding value is undefined from the parent.
I think if a value is bound (identifiable from the compiled instructions, I guess), then that value will be assigned, even if it is undefined
. One can always employ setters in @bindable
, if that does not suffice.
from aurelia.
After some moment of aha, I think we can at least partially address this issue by making empty binding as no binding. For custom attributes, empty binding mean an empty string as expression, for example:
<div my-attribute>
I don't think anyone would want to say: create a custom attribute my-attribute
, and let it have an empty string as value.
With this change, the default value should be able to be retained when there's no actual binding.
For when there's actual binding, but empty values (undefined
/null
/""/actual value
), it's the actual value so I think we can leave it alone, like in these example:
<div my-attribute="val">
<div my-attribute.bind="`...`">
<div my-attribute="${...}">
from aurelia.
I created a PR here #1930
It should address the issue with the cases you mentioned @ekzobrain
For the template
<div my-attr="val">
I think the intention is too clear that the attribute wants to bind to the primary bindable with a value val
literal string, we probably shouldn't change that.
from aurelia.
I agree with this partial solution. At least it solves the main issue when attribute is used without any intentional value
from aurelia.
Related Issues (20)
- [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
- 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 10
- [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 9
- 2.0.0-beta.12 - Custom elements instances are now different HOT 10
- [feature request] ability to typecheck template
- RFC: Enhancements for Overriding Registrations in Aurelia DI Container HOT 6
- bindable decorator should not be giving a runtime error HOT 28
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.