Skip to content
This repository has been archived by the owner on Dec 23, 2019. It is now read-only.

Commit

Permalink
Bugix/undefined promise (#21)
Browse files Browse the repository at this point in the history
* return undefined vs null / clear() returns promise

* update changelog
  • Loading branch information
cvburgess authored Jan 25, 2018
1 parent fdd6b80 commit 5f0abc1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 0.9.2

- Fix `cache.clear()` to return a promise
- Return `undefined` when the cache has no results for a given key

## 0.9.1

- Set `__fromCache = true` when returning results from cache
Expand Down
4 changes: 2 additions & 2 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ var set = exports.set = function set(cacheKey, value) {

var getSync = exports.getSync = function getSync(cacheKey, defaultValue) {
var result = _store2.default.get(cacheKey) || defaultValue;
return result ? _extends({}, result, { __cacheKey: cacheKey, __fromCache: true }) : null;
return result ? _extends({}, result, { __cacheKey: cacheKey, __fromCache: true }) : undefined;
};

var get = exports.get = function get(cacheKey, defaultValue) {
return Promise.resolve(getSync(cacheKey, defaultValue));
};

var clear = exports.clear = function clear() {
return _store2.default.clearAll();
return Promise.resolve(_store2.default.clearAll());
};

var observeData = function observeData(actionName, dataFn, onNext, onError) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "withdata",
"version": "0.9.1",
"version": "0.9.2",
"description": "Utilities for managing data via props. Inspired by apollo-client.",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export const set = (cacheKey, value, maxAge = defaultConfig.maxAge) => {

export const getSync = (cacheKey, defaultValue) => {
const result = store.get(cacheKey) || defaultValue;
return result ? { ...result, __cacheKey: cacheKey, __fromCache: true } : null;
return result ? { ...result, __cacheKey: cacheKey, __fromCache: true } : undefined;
};

export const get = (cacheKey, defaultValue) =>
Promise.resolve(getSync(cacheKey, defaultValue));

export const clear = () => store.clearAll();
export const clear = () => Promise.resolve(store.clearAll());

export const observeData = (
actionName,
Expand Down

0 comments on commit 5f0abc1

Please sign in to comment.