Allow passing arguments to the `.wait()` callback #33

Closed
bemson opened this Issue Apr 4, 2013 · 1 comment

Comments

Projects
None yet
1 participant
Owner

bemson commented Apr 4, 2013

The .wait() method fires a given callback when the delay expires; the callback can also be another program state. In both cases, the only way to pass arguments to the callback, is to store it in a shared (i.e., public) location.

The example below demonstrates how the .data property must be used as a bridge between the current navigation and the .wait() callback.

var delayCall = new Flow({
  _data: 'fnc',
  _on: function (callback) {
    this.data.fnc = callback;
    this.wait('invoke', 0);
  },
  invoke: function () {
    this.data.fnc();
  }
});

Support pass-through arguments in .wait()

The .wait() method could support passing-through arguments to the callback. The method would pass all arguments after the second, to the given function or navigation target.

Below, demonstrates the earlier example, using additional arguments.

var delayCall = new Flow({
  _on: function (callback) {
    this.wait('invoke', 0, callback);
  },
  invoke: function (callback) {
    callback();
  }
});

This approach removes the "glue" code needed, when passing values asynchronously.

Owner

bemson commented Apr 4, 2013

Commit f7d7bf7 - added functionality. Need to write tests before closing.

@ghost ghost assigned bemson Apr 5, 2013

@bemson bemson closed this in 2443c6b Apr 11, 2013

bemson added a commit that referenced this issue Apr 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment