Flotype / now

NowJS makes it easy to build real-time web apps using JavaScript
http://www.nowjs.com
MIT License
1.91k stars 175 forks source link

NowJS Function Chaining #170

Closed ghost closed 12 years ago

ghost commented 12 years ago

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

steveWang commented 12 years ago

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.

steveWang commented 12 years ago

See chaining branch. Minimally tested and highly experimental.

ghost commented 12 years ago

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

steveWang commented 12 years ago

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