Skip to content

Commit

Permalink
Don't brake store context for isCacheableValue method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrusavin committed Mar 10, 2018
1 parent 2d9dece commit d0da236
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/caching.js
Expand Up @@ -38,7 +38,7 @@ var caching = function(args) {
if (typeof args.isCacheableValue === 'function') {
self._isCacheableValue = args.isCacheableValue;
} else if (typeof self.store.isCacheableValue === 'function') {
self._isCacheableValue = self.store.isCacheableValue;
self._isCacheableValue = self.store.isCacheableValue.bind(self.store);
} else {
self._isCacheableValue = function(value) {
return value !== undefined;
Expand Down
18 changes: 18 additions & 0 deletions test/caching.unit.js
Expand Up @@ -1234,4 +1234,22 @@ describe("caching", function() {
});
});
});

describe("when using store's isCacheableValue method", function() {
it("should not break its' context", function() {
var store = {
isCacheableValue: function() {
if (this !== store) {
throw new Error("Broken store context");
}
},
get: function() {},
set: function() {},
};

cache = caching({store: store});

assert.doesNotThrow(cache._isCacheableValue);
});
});
});

0 comments on commit d0da236

Please sign in to comment.