20110626

Time-buffered WUI update /javascript

When it comes to UI (and it naturally comes to js), there often are routines that you would like to perform on a certain event, but not necessarily on each such event, that is, just enough to keep a view updated at most times.
For instance, there are items being added to a sorted list: you'd like to sort the list whenever a new item arrives, but when a bunch of items arrive at once (over a short period of time), you'd like to postpone sorting to the last item in the bunch (for obvious reasons). And you want to keep things simple and refrain from event queuing, optimizing the sort routine and other complex stuff.
Well, in that case, something I call time buffering may help you. If your event handler looks like this:

function _onNewItem(item) {
_addItem(item);
_sortList();
}

With time buffering it'll look like this:

function _onNewItem(item) {
_addItem(item);
_timeBuffer("sort_list", _sortList, 500, 2000);
}

Not much of a change, eh? And the killer routine?

I'm sure you can fix my style (you're welcome) and add support for removing such list elements -- and associated actions -- cleanly (with something like function _timeBufferNoMore(act)), but you get the idea.

1 comment:

  1. These machines have a couple of payline, that means that seen symbols that are not aligned on the principle horizontal could also be} thought-about as winning combos. Traditional three-reel slot machines generally have one, three, or five paylines whereas video slot machines may have 9, 15, 25, or as many as 1024 completely different paylines. Most settle for variable numbers 원 엑스 벳 of credits to play, with 1 to fifteen credits per line being typical. The higher the amount bet, the higher the payout might be if the participant wins. Every respected slots casino will supply gamers the choice to play slots for free.

    ReplyDelete