02 Apr 2013, 08:11
Im.png_pragsmall

Paul Samuels (1 post)

I noticed that it is quite easy (I did it twice) when typing in the examples to forget to pop a timeout which leads to confusion.

Would it be worth adding a global sandwich method to make sure that the call is always balanced?

An example might look like

function performWithTimeout(timeout, steps) {
  var target = UIATarget.localTarget();
  target.pushTimeout(timeout);
  steps();
  target.popTimeout();
};

//

UIALogger.logMessage('' + UIATarget.localTarget().timeout());

performWithTimeout(0.1, function() {
  UIALogger.logMessage('' + UIATarget.localTarget().timeout());
});

UIALogger.logMessage('' + UIATarget.localTarget().timeout());

//=> 5
//=> 0.1
//=> 5
10 Apr 2013, 13:27
Avatar_pragsmall

Jonathan Penn (43 posts)

I think that idea has merit. The problem is that you change the meaning of @this”@in the function you pass to @performWithTimeout()@. I had to make a lot of tradeoffs on how much JavaScript to discuss in the book because a lot of people coming to read this aren’t web developers. I think this idea is best left as an exercise for the reader.

Besides, I advocate that the logic that accesses the elements with the custom timeout should be wrapped in a screen object method. That means you won’t be making this error over and over again because you’ll get it right in one place.

  You must be logged in to comment