Skip to content

Commit

Permalink
Merge pull request #667 from sdesai/fixEmptyDerefOnGetError
Browse files Browse the repository at this point in the history
Fixed deref completing, without onNext'ing a bound model, if the preload paths fail
  • Loading branch information
sdesai committed Dec 15, 2015
2 parents 96201d6 + b9ad3a6 commit a18e21c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/deref/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ module.exports = function deref(boundPathArg) {
flatMap(function(boundModel) {
if (Boolean(boundModel)) {
if (pathsCount > 0) {

return boundModel.get.
apply(boundModel, paths).
map(function() {
return boundModel;
}).
catch(Rx.Observable.empty());
catch(Rx.Observable.of(boundModel)).
take(1);

}
return Rx.Observable.return(boundModel);
} else if (pathsCount > 0) {
Expand Down
64 changes: 64 additions & 0 deletions test/falcor/bind/bind-cases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,56 @@ describe('Deref', function() {

expect(out.value).to.equals(undefined);
});

it('should deliver successfully bound model if preload path errors', function(done) {

var modelCache = getCache();
var model = new Model({ cache: modelCache });

var onNext = sinon.spy();
var onError = sinon.spy(function() {
assert.fail(0, 1, "Did not expect error handler to be invoked");
});

model.
deref(['lolomo', 0], [1, 'item', 'info']).
doAction(onNext, onError, function() {
var boundModel = onNext.getCall(0).args[0];

expect(onNext.callCount).to.equal(1);
expect(boundModel).to.not.equal(model);
expect(boundModel._path).to.deep.equal(
['lists', 'c595efe8-4de0-4226-8d4a-ebe89d236e2f_fcce4c47-7b36-456b-89ac-bde430a24ca8']
);

}).
subscribe(noOp, done, done);
});

it('should deliver successfully bound model if one preload path succeeds, and one preload path errors', function(done) {

var modelCache = getCache();
var model = new Model({ cache: modelCache });

var onNext = sinon.spy();
var onError = sinon.spy(function() {
assert.fail(0, 1, "Did not expect error handler to be invoked");
});

model.
deref(['lolomo', 0], [[0,1], 'item', 'info']).
doAction(onNext, onError, function() {
var boundModel = onNext.getCall(0).args[0];

expect(onNext.callCount).to.equal(1);
expect(boundModel).to.not.equal(model);
expect(boundModel._path).to.deep.equal(
['lists', 'c595efe8-4de0-4226-8d4a-ebe89d236e2f_fcce4c47-7b36-456b-89ac-bde430a24ca8']
);

}).
subscribe(noOp, done, done);
});
});

function getCache() {
Expand Down Expand Up @@ -213,9 +263,23 @@ function getCache() {
"$type": "atom",
}
},
"1":{
"item": {
"$type": "ref",
"value": ["videos", "err"],
}
}
},
},
"videos": {
"err": {
"info": {
"$type": "error",
"value": {
"message": "errormsg"
}
}
},
"80041601": {
"info": {
"value": {
Expand Down

0 comments on commit a18e21c

Please sign in to comment.