sunnylqm / react-native-storage

local storage wrapper for both react-native and browser. Support size controlling, auto expiring, remote data auto syncing and getting batch data in one query.
MIT License
3.02k stars 268 forks source link

[v1.0.0] getAllDataForKey crash #216

Closed kolyneh closed 5 years ago

kolyneh commented 5 years ago

使用v1.0.0版本出现 getAllDataForKey crash,错误信息如下: undefined is not an object (evaluating '_this._m.__keys__') 退回v0.2.4版本就没问题。

juhasuni commented 5 years ago

The problem is, that getAllDataForKey calls getIdsForKey, which in turn doesn't wait for the internal _mapPromise to resolve and for that reason this._m is undefined. In order to fix it, the getIdsForKey needs to be changed asynchronous and it must wait for the internal _mapPromise to be resolved, like most other async methods do. The documentation actually already says that getIdsForKey returns a Promise, but it doesn't.

As a workaround, you can call load before getAllDataForKey, like this:

try { await storage.load({key}); } catch(e) {};
let data = await storage.getAllDataForKey(key);
sunnylqm commented 5 years ago

That's true. Thanks for reminding! @juhasuni

sunnylqm commented 5 years ago

Should be fixed in https://github.com/sunnylqm/react-native-storage/commit/adfcc82beca1c50238c8d71d8d913aa308e67140