You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/databinding/@bind.md
+17-6Lines changed: 17 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -49,12 +49,6 @@ In JavaScript the only difference is how - if at all - the decorated property is
49
49
myNumber;
50
50
```
51
51
52
-
Change events are fired for the decorated *component property* when the *target element* fires change events.
53
-
54
-
> See example apps ["bind-two-way-change-events"](../../examples/bind-two-way-change-events) (TypeScript) and ["bind-two-way-change-events-jsx"](../../examples/bind-two-way-change-events-jsx) (JavaScript/JSX).
55
-
56
-
As with one-way bindings, setting the *component property* to `undefined` resets the *target property* to its initial value for when the binding was first established.
57
-
58
52
## @bind(config)
59
53
60
54
Like [`@bind(path)`](#bindpath) or [`@bindAll(bindings)`](./@bindAll.md), but allows to give additional options as supported by [`@property`](./@property.md).
@@ -104,3 +98,20 @@ A [`typeGuard`](./@property.md#configtypeguard) may be given to perform value ch
104
98
105
99
A [`type`](./@property.md#configtype) may be given to enforce type checks in JavaScript.
106
100
101
+
### Properties eligible for bindings
102
+
103
+
Any *component property* can be used for two-way bindings, unless it's explicitly implemented with a setter and getter, or with `Object.defineProperty`. These are not supported. The target property needs to generate change events for the two-way binding to work. This is already the case for all built-in properties of Tabris.js widgets.
104
+
105
+
> See example apps ["bind-two-way-change-events"](../../examples/bind-two-way-change-events) (TypeScript) and ["bind-two-way-change-events-jsx"](../../examples/bind-two-way-change-events-jsx) (JavaScript/JSX).
106
+
107
+
If the target widget itself is a custom component the recommended way to implement change events is using [`@property`](./@property.md). Note that there is no need to explicitly create an event API, `@bind` can 'talk' directly to `@property`. However, an explicit implementation is also possible.
108
+
109
+
## Edge Cases
110
+
111
+
As with one-way bindings, setting the *component property* to `undefined` resets the *target property* to its initial value for when the binding was first established. The component property will also adopt that value, so both stay in syc.
112
+
113
+
If the *component property* converts or ignores the incoming value of the *target property*, the target property will follow and also bet set to the new component property value.
114
+
115
+
If a *target property* converts or ignores the incoming value of the *component property*, the component property will ignore that and keep its own value. The two properties are out-of-sync in this case.
116
+
117
+
If either property throws when set, the error will be propagated to the caller that originally caused the value change. In this case the two properties *may* end up out-of-sync.
0 commit comments