K
Keith Hughitt
Hi all,
I was wondering if anyone had any suggestions for alternative ways for
multiple objects to keep track of a single variable? Initially, I
thought of just using a single (YUI) Custom event to let any
interested objects know that the value has changed.
e.g.
Event 1 --> Function A
|--> Function B
|--> Function C
And this would work fine if sequence was not important. Because,
however, Function C relies on Function A having been executed first, I
created a new event and chained them:
Event 1 --> Function A --> Event 2 --> Function C
|--> Function B
And this worked fine for a while, but alas, I have a new condition
which resulted in the above system not working properly. In the new
system, C depends not only on A having been executed, but also on B,
*BUT*, only if B's associated Object has been instantiated. So for the
moment , this is the solution I've come up with:
Function D --> Event 1 --> Function A
| | --> Function B (optional)
|
|--> Event 2 --> Function C
While this works, it is not the most straight-forward way of doing
things. It would be much easier to simply keep a global variable with
the value that Functions A-C depend on, and refer to it, however, I'd
like to avoid using global variables if at all possible.
Another possibility I've considered is to use a static class method
(e.g. http://blogger.xs4all.nl/peterned/archive/2006/08/15/114545.aspx)
to fetch the desired value when needed, but this would require re-
writing the class, which is also something I'd like to avoid.
Anyone have any suggestions for a better solution? I Originally tried
asking this question on the YUI mailing-list since It involved using
YUI custom events, but have not gotten any response there. Any advice
would be greatly appreciated!
Thanks
Keith
I was wondering if anyone had any suggestions for alternative ways for
multiple objects to keep track of a single variable? Initially, I
thought of just using a single (YUI) Custom event to let any
interested objects know that the value has changed.
e.g.
Event 1 --> Function A
|--> Function B
|--> Function C
And this would work fine if sequence was not important. Because,
however, Function C relies on Function A having been executed first, I
created a new event and chained them:
Event 1 --> Function A --> Event 2 --> Function C
|--> Function B
And this worked fine for a while, but alas, I have a new condition
which resulted in the above system not working properly. In the new
system, C depends not only on A having been executed, but also on B,
*BUT*, only if B's associated Object has been instantiated. So for the
moment , this is the solution I've come up with:
Function D --> Event 1 --> Function A
| | --> Function B (optional)
|
|--> Event 2 --> Function C
While this works, it is not the most straight-forward way of doing
things. It would be much easier to simply keep a global variable with
the value that Functions A-C depend on, and refer to it, however, I'd
like to avoid using global variables if at all possible.
Another possibility I've considered is to use a static class method
(e.g. http://blogger.xs4all.nl/peterned/archive/2006/08/15/114545.aspx)
to fetch the desired value when needed, but this would require re-
writing the class, which is also something I'd like to avoid.
Anyone have any suggestions for a better solution? I Originally tried
asking this question on the YUI mailing-list since It involved using
YUI custom events, but have not gotten any response there. Any advice
would be greatly appreciated!
Thanks
Keith