react-native-storage
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "react-native-storage", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "This is a local storage wrapper for both react-native(AsyncStorage) and browser(localStorage). ES6/babel is needed.", | ||
@@ -5,0 +5,0 @@ "main": "storage.js", |
@@ -8,4 +8,13 @@ # react-native-storage | ||
## Install 安装 | ||
npm install react-native-storage --save | ||
## Usage 使用说明 | ||
### Import 导入 | ||
You need to use [babel](https://babeljs.io/) to enable module import. For React-Native development, add 'es6.modules' to the **whitelist** in `node_modules/react-native/packager/transformer.js` | ||
你需要使用[babel](https://babeljs.io/)来支持模块导入功能。 如果是React-Native开发,在`node_modules/react-native/packager/transformer.js的whitelist`中加入'es6.modules'即可。 | ||
import Storage from 'react-native-storage' | ||
### Save & Load 保存和读取 | ||
@@ -70,3 +79,16 @@ Storage.save(id, data, global, expires) | ||
These methods are ready to use, while the document is WIP(work in progress). | ||
以上两个方法已经可以使用,但具体说明待续。 | ||
If you want to get several data to in one action, then use these methods. Examples: | ||
如果你想在一次操作中获取多个数据,那就使用上面的两个方法。示例: | ||
Storage.getBatchDataWithKeys(['user_123', 'company_321', 'token']) | ||
.then( results => { | ||
results.forEach( result => { | ||
console.info(result); | ||
}) | ||
}) | ||
Storage.getBatchDataWithIds('images', ['1001', '1002', '1003']) | ||
.then( ... ) | ||
There is a notable difference between the two methods except the arguments. **getBatchDataWithKeys** will invoke different sync methods(since the keys are different) one by one when corresponding data is missing. However, **getBatchDataWithIds** will collect missing data, push their ids to a array, then pass the array to the corresponding sync method(to avoid too many requests), so you need to implement array query on server end. | ||
这两个方法除了参数形式不同,还有个值得注意的差异。**getBatchDataWithKeys**会在数据缺失时挨个调用不同的sync方法(因为key不同)。但是**getBatchDataWithIds**却会把缺失的数据统计起来,将它们的id收集到一个数组中,然后一次传递给对应的sync方法(避免挨个查询导致同时发起大量请求),所以你需要在服务端实现通过数组来查询返回。 |
14433
92