NowJS Function Chaining #170

Closed
ghost opened this Issue Jan 7, 2012 · 4 comments

Comments

Projects
None yet
1 participant
@ghost

ghost commented Jan 7, 2012

I am trying to chain functions then make them accessible for server access. Does now support this feature?

Chain example: now.calc.add(2).subtract(2).result();

Thanks

Contributor

steveWang commented Jan 7, 2012

Just have each function aside from the last one return this; -- it should work.

For instance:

now.calc = {
  val: 0,
  add: function (i) {
    this.val += i;
    return this;
  },
  subtract: function (i) {
    this.val -= i;
    return this;
  },
  result: function () {
    return this.val;
  }
};

Actually, wait, you're probably referring to defining these functions server-side, yes? You'll probably want, first of all, to capture the result in a callback passed to now.calc.result(). Also, I'm not entirely sure, will sift through code. I'll get back to you in a few.

edit: Nope, not supported. Awkward to implement fully.

Contributor

steveWang commented Jan 7, 2012

See chaining branch. Minimally tested and highly experimental.

steveWang closed this Jan 7, 2012

@ghost

ghost commented Jan 7, 2012

Thanks for the help and I will take a look at the chaining branch.
I understand this is not a desirable feature to implement.

Contributor

steveWang commented Jan 7, 2012

It's not that it's undesirable; rather, it's just awkward and not quite the way the rest of NowJS works.

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