Chapter 4 Using Activities in ADL
One such NRO is the vanillaNro class. This NRO sends only the client data in its messages. For example, suppose we want to simplify our mouse tracking program shown above so that it only reports the type of the last mouse action, not the location. In this case, the (x,y) coordinates of the mouse activity are not needed. We could instead use three instances of the vanillaNro object defined as follows:
vanillaNro {'Create, 'MouseDown, self, 'MouseTrack, "Down"} => downNro; vanillaNro {'Create, 'MouseUp, self, 'MouseTrack, "Up"} => upNro; vanillaNro {'Create, 'MouseMove, self, 'MouseTrack, "Move"} => moveNro;We can then rewrite the MouseTrack method as show in Figure 4.6.
on MouseTrack: string clientData { reportLabel.label = "Mouse" & clientData & "activity"; } |
An even simpler NRO available in the standard library that sends no arguments when an event triggers the activity. This is the simpleNro class. Any method that handles an activity subscribed to using a simpleNro must have no arguments.
For example, we could rewrite the mouse tracking program in Figure 4.6 so that each of the three activities being subscribed to send a message to a different method. In this case, we could use the simpleNro class instead of the vanillaNro class, as follows:
simpleNro {'Create, 'MouseDown, self, 'MousePush, ""} => downNro; simpleNro {'Create, 'MouseUp, self, 'MouseRelease, ""} => upNro; simpleNro {'Create, 'MouseMove, self, 'MouseChange, ""} => moveNro;In this case, the method named MouseTrack shown in Figure 4.6 would be replaced by three simpler methods named MousePush, MouseRelease and MouseChange,as shown in Figure 4.7.
Generated with Harlequin WebMaker