Also would be great if one could define more than reference in handler tag
Like this
<handler name="eventName" reference="eventSender1, eventSender2,
eventSender3" args="eventArg">
...
</handler>
Or is this already possible?
- rami
10.2.2010 21:47, Rami Ojares kirjoitti:
Hi,
Here is a piece of typical OL xml
<SomeClass height="${this.program.duration * x + y}">
<attribute name="program"/>
</SomeClas>
This creates automatically a handler something along these lines
<handler name="onduration" reference="this.program" args="newDuration">
this.setAttribute("height", this.program.duration * x + y);
</handler>
In my app it is very common that not only the duration of the program
changes but also the program
attribute of SomeClass changes too.
That's when things go wrong.
I have ended up writing my own handlers in many places to alleviate
this issue.
So my question is have others suffered from this also?
Sometimes this issue arises also if the program is initialized so late
that the reference evaluates to null or undefined when the handler is
instantiated. And then the constraint does not work at all.
Here is an exmaple that shows you what I mean.
(I tried to make it as short as possible to demonstrate the issue)
<canvas debug="true">
<node name="dataNode1">
<attribute name="data" type="string" value="AAA"/>
</node>
<node name="dataNode2">
<attribute name="data" type="string" value="111"/>
</node>
<view name="dataConsumer" width="100" height="100" bgcolor="dodgerblue">
<attribute name="dataSrc" value="${canvas.dataNode1}"/>
<!-- If you don't provide initial value you will not get text at all
no matter how much you push the button -->
<!-- <attribute name="dataSrc"/> -->
<text text="${'[' + parent.dataSrc.data + ']'}"/>
</view>
<!-- This button tries to set a new value to dataConsumer but fails -->
<button text="Push" y="100">
<handler name="onclick">
dataConsumer.setAttribute("dataSrc", canvas.dataNode2);
</handler>
</button>
</canvas>
So here is my suggestion:
when writing a constraint like
- obj1.obj2.attr1
- this.obj1.obj2.attr1
- classroot.obj1.obj2.attr1
Then the following code would be autogenerated
- code for the method that "handles" the constraint logic (already
done in the current version)
- Delegate that calls that method (already done in the current version)
- delegate would be registered to listen onattr1 event from obj2
(already done in the current version)
- delegate would be registered to listen onobj2 event from obj1 (new)
- delegate would be registered to listen onobj1 event from this (first
2 cases) or classroot (new)
I don't know what the performance considerations for this would be but
I remember reading somewhere that delegates that do nothing have a
negligible performance impact.
This would make the constraint system behave more as expected because
then it would truly follow the value you have declaratively commanded
that it should follow.
What do you think?
- rami