Friday, May 12, 2006

Watch Manager -- Beating The System

Download:
Required:MTASC Compliant Delegate Class
Watch Manager Class

Example Files
Note: You may have to change the class names and import data in order to make sure your classpath is correct.




I've been writing this class on and off for fun (it really is a fetish) in the past week or so. It's not ment to replace events or even be used in an every day situtation if at all. I mainly wrote it to see if it could be done and, guess what, it can. The core of this class is two static methods: subscribe and unsubscribe. Subscribe adds the watch to the watch registry inside the class. Unsubscribe removes the watch from the registry.

Subscribe has four parameters.

  • $obj: A string representation of the object that contains the property to watch. Is 100% independent of scope.

  • $prop: A string that contains the property name to watch within $obj.

  • $scope: The scope that contains $obj[$prop].

  • $callback: Callback function for the watch. If the callback is outside of $scope you must use Delegate.create to reassign scope.



Unsubscribe only has one.

  • $wObj:An object that's returned from the subscribe method.



The watch manager class eliminates all the previous limitations of Object.watch I listed in this post.

If you peep in the example files you can see exactly how it's used. If there are any bugs I'd like to know.

0 Comments:

Post a Comment

<< Home