Thilo (3) [Avatar] Offline
#1
I really enjoy reading this great book! There is one issue though that I stumbled upon:

The onResize() function currently has the (slightly incorrect) structure:

onResize = function (){
  if ( stateMap.resize_idto ) { return true; }
  spa.chat.handleResize();  // adjust your own SPA contents...
  stateMap.resize_idto = setTimeout(
     function (){ stateMap.resize_idto = undefined; },
     configMap.resize_interval
  );
  return true;
};


For me, this works only sometimes. (I was trying to make a DOM element fit exactly in between others...)

The catch is that the current onResize() manages to execute only 1 resize event per interval (200ms). But it fails to react to the last resize event in a sequence. Think of a user manually resizing a window. One must make sure that the SPA adjusts itself to the very last resize event as this is the final size after the user is done resizing.

The fix is simple: put your action inside the function that is executed when the timeout fires:

onResize = function (){
  if ( stateMap.resize_idto ) { return true; }
  stateMap.resize_idto = setTimeout(
     function (){ 
        stateMap.resize_idto = undefined;
        spa.chat.handleResize();  // adjust your own SPA contents...
     },
     configMap.resize_interval
  );
  return true;
};


michael.mikowski (247) [Avatar] Offline
#2
This is correct. I was young and foolish when I wrote that smilie. Seriously though, I'll put that in the errata. Thanks!