Skip to content

Instantly share code, notes, and snippets.

@cburgdorf
Created August 25, 2011 11:49
Show Gist options
  • Save cburgdorf/1170494 to your computer and use it in GitHub Desktop.
Save cburgdorf/1170494 to your computer and use it in GitHub Desktop.
cachedObservable
//This doesnt work (Fails on second try)
var cachedObservable;
var observableFms = Rx.Observable.If(function() {
return cachedObservable !== undefined;
},
cachedObservable,
Rx.Observable.Defer(function() {
cachedObservable = service.getObservableFmsAuswertungForTour(data.ID);
return cachedObservable;
}));
//This does work
var cachedObservable;
var observableFms = Rx.Observable.If(function() {
return cachedObservable !== undefined;
},
Rx.Observable.Defer(function(){
return cachedObservable;
},
Rx.Observable.Defer(function() {
cachedObservable = service.getObservableFmsAuswertungForTour(data.ID);
return cachedObservable;
}));
What's wrong with the first one? Even I can see in the debugger that the cachedObservable was set correctly from the first call, the second call fails with "undefined has no method Subscribe". The second approach does work however.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment