Additional Observable Reactive Operators

Hi Fuser Team.

Encountered some inconvenice with Observables today. We need reactive operators that could:

  1. Observable.unshift(); (add values to beginning of list)
  2. Observable.reverse(); (reverse list)

… etc.

These would make them that much more awesome :smiley:

Cheers,

Elizabeth

Hey Elizabeth, great suggestions I’ll make a little ticket to look into these.

Thanks!

Honestly they should have all the array methods. I’m not sure if this would work:

Object.getOwnPropertyNames(Array.prototype).forEach(function(prop) {
  if(prop !== 'length' && prop !== 'constructor' && prop !== 'toString' && prop !== 'toLocaleString') {
    Observable.prototype[prop] = function() {
      var results = Array.prototype[method].apply(this._values, arguments);
      if(results instanceof Array) {
          return Observable(results).expand();
      } else {
          return results;
      }
    }
  }
});

Didn’t test the above code

Hi Edwin,

Fair points but I think what we (at fuse) have to be careful with is not to be too confusing regarding how Observable of arrays is different from a Observable of multiple values.

Observable([{a:1},{b:2},{c:3}]) != Observable({a:1},{b:2},{c:3})

Both work, but fuse is structural aware of the second one, which allows us to do smarter things in UX.

Thanks for posting though

@chris I know that Observable([{a:1},{b:2},{c:3}]) != Observable({a:1},{b:2},{c:3}) that’ what that second if statement was for, again haven’t tested the code yet I will do in a bit