Permalink
Browse files

0.2.0

  • Loading branch information...
sunnylqm committed May 2, 2017
1 parent 97f0a47 commit ffcff489db29a042ede710593790598811d0c353
Showing with 2,532 additions and 323 deletions.
  1. +4 −0 .babelrc
  2. +1 −1 .travis.yml
  3. +7 −3 README-CHN.md
  4. +7 −3 README.md
  5. +24 −24 __tests__/basic-function-test.js
  6. +112 −204 __tests__/batch-and-sync-test.js
  7. +8 −5 package.json
  8. +75 −83 storage.js
  9. +2,294 −0 yarn.lock
View
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["transform-object-rest-spread"]
}
View
@@ -1,3 +1,3 @@
language: node_js
node_js:
- "5"
- "7"
View
@@ -99,7 +99,7 @@ var storage = new Storage({
// 除非你手动移除,这些数据会被永久保存,而且默认不会过期。
storage.save({
key: 'loginState', // 注意:请不要在key中使用_下划线符号!
rawData: {
data: {
from: 'some other site',
userid: 'some userid',
token: 'some token'
@@ -175,7 +175,7 @@ var storage = new Storage({
storage.save({
key: 'user', // 注意:请不要在key中使用_下划线符号!
id: '1001', // 注意:请不要在id中使用_下划线符号!
rawData: userA,
data: userA,
expires: 1000 * 60
});
@@ -250,7 +250,7 @@ storage.clearMap();
storage.save({
key: 'user',
id,
rawData: json.user
data: json.user
});
if (someFlag) {
@@ -313,6 +313,10 @@ storage.getBatchDataWithIds({
### 更新日志
#### 0.2.0
1. `rawData`参数已弃用,请使用`data`参数
2. jest版本升级到19.0.0
#### 0.1.5
1. 现在可以给sync方法传递额外参数
2. 修复clearMap的一点问题
View
@@ -96,7 +96,7 @@ var storage = new Storage({
// They are permanently stored unless you remove.
storage.save({
key: 'loginState', // Note: Do not use underscore("_") in key!
rawData: {
data: {
from: 'some other site',
userid: 'some userid',
token: 'some token'
@@ -164,7 +164,7 @@ var userA = {
storage.save({
key: 'user', // Note: Do not use underscore("_") in key!
id: '1001', // Note: Do not use underscore("_") in id!
rawData: userA,
data: userA,
expires: 1000 * 60
});
@@ -244,7 +244,7 @@ storage.sync = {
storage.save({
key: 'user',
id,
rawData: json.user
data: json.user
});
if (someFlag) {
@@ -311,6 +311,10 @@ There is a notable difference between the two methods except the arguments. **ge
### Changelog
#### 0.2.0
1. `rawData` is now deprecated, use "data" instead!
2. Upgrade jest to 19.0.0
#### 0.1.5
1. Now you can pass extra params to sync method.
2. Fix clearMap
@@ -1,7 +1,7 @@
jest.dontMock('../error.js');
jest.dontMock('../storage.js');
let Storage = require('../storage.js');
import Storage from '../storage';
const SIZE = 10,
DEFAULTEXPIRES = 1000 * 3600;
let localStorage = new Storage({
@@ -19,11 +19,11 @@ let stores = { localStorage, asyncStorage };
describe('react-native-storage: basic function', () => {
Object.keys(stores).map(storageKey => {
let storage = stores[storageKey];
it('accepts parameters in constructor' + `(${storageKey})`, () => {
test('accepts parameters in constructor' + `(${storageKey})`, () => {
expect(storage._SIZE).toBe(SIZE);
expect(storage.defaultExpires).toBe(DEFAULTEXPIRES);
});
pit('saves and loads any type of data' + `(${storageKey})`, () => {
test('saves and loads any type of data' + `(${storageKey})`, () => {
let testCases = {
testNumber: 11221,
testString: 'testString',
@@ -44,7 +44,7 @@ describe('react-native-storage: basic function', () => {
tasks.push(
storage.save({
key,
rawData: testCases[key]
data: testCases[key]
}).then(() =>
storage.load({
key
@@ -57,7 +57,7 @@ describe('react-native-storage: basic function', () => {
storage.save({
key,
id: 1,
rawData: testCases[key]
data: testCases[key]
}).then(() =>
storage.load({
key,
@@ -75,7 +75,7 @@ describe('react-native-storage: basic function', () => {
}
});
});
pit('rejects when no data found and no sync method' + `(${storageKey})`, () => {
test('rejects when no data found and no sync method' + `(${storageKey})`, () => {
let testKey1 = 'testKey' + Math.random(),
testKey2 = 'testKey' + Math.random(),
testId2 = 'testId' + Math.random();
@@ -105,10 +105,10 @@ describe('react-native-storage: basic function', () => {
});
});
pit('rejects when data expired and no sync method' + `(${storageKey})`, () => {
test('rejects when data expired and no sync method' + `(${storageKey})`, () => {
let originGetTime = Date.prototype.getTime;
let starttime = 0;
Date.prototype.getTime = jest.genMockFn().mockImpl(() => {
Date.prototype.getTime = jest.fn(() => {
return starttime += 100;
});
let testKey1 = 'testKey' + Math.random(),
@@ -120,7 +120,7 @@ describe('react-native-storage: basic function', () => {
let tasks = [
storage.save({
key: testKey1,
rawData: testData1,
data: testData1,
expires: 1,
}).then(() =>
storage.load({
@@ -134,7 +134,7 @@ describe('react-native-storage: basic function', () => {
storage.save({
key: testKey2,
id: testId2,
rawData: testData2,
data: testData2,
expires: 1,
}).then(() =>
storage.load({
@@ -155,7 +155,7 @@ describe('react-native-storage: basic function', () => {
Date.prototype.getTime = originGetTime;
});
});
//it('overwrites "key+id" data when loops over(exceeds SIZE)', () => {
//test('overwrites "key+id" data when loops over(exceeds SIZE)', () => {
// let testKey = 'testKey' + Math.random(),
// testId = 'testId' + Math.random(),
// testData = 'testData' + Math.random();
@@ -164,14 +164,14 @@ describe('react-native-storage: basic function', () => {
// storage.save({
// key: testKey,
// id: testId,
// rawData: testData
// data: testData
// });
// tmpIndex1 = storage._m.index;
// for (let i = 0; i < SIZE - 1; i++) {
// storage.save({
// key: 'testKey' + Math.random(),
// id: 'testId' + Math.random(),
// rawData: 'testData' + Math.random()
// data: 'testData' + Math.random()
// });
// }
//
@@ -190,7 +190,7 @@ describe('react-native-storage: basic function', () => {
// storage.save({
// key: 'testKey' + Math.random(),
// id: 'testId' + Math.random(),
// rawData: 'testData' + Math.random()
// data: 'testData' + Math.random()
// });
// tmpIndex2 = storage._m.index;
// storage.load({
@@ -215,18 +215,18 @@ describe('react-native-storage: basic function', () => {
//});
pit('removes data correctly' + `(${storageKey})`, () => {
test('removes data correctly' + `(${storageKey})`, () => {
let testKey1 = 'testKey1' + Math.random(),
testKey2 = 'testKey2' + Math.random(),
testId2 = 'testId2' + Math.random(),
testData1 = 'testData1' + Math.random(),
testData2 = 'testData2' + Math.random();
let ret1 = [undefined, undefined], ret2 = [undefined, undefined];
let task = (key, id, rawData, retArray) => {
let task = (key, id, data, retArray) => {
return storage.save({
key,
id,
rawData
data
}).then(() => {
return storage.load({
key,
@@ -254,15 +254,15 @@ describe('react-native-storage: basic function', () => {
});
});
pit('gets all data for key correctly' + `(${storageKey})`, () => {
test('gets all data for key correctly' + `(${storageKey})`, () => {
let key = 'testKey' + Math.random(),
testIds = [Math.random(), Math.random(), Math.random()],
testDatas = [Math.random(), Math.random(), Math.random()];
return Promise.all(
testIds.map((id, i) => storage.save({
key,
id,
rawData: testDatas[i]
data: testDatas[i]
}))
)
.then(() => {
@@ -273,7 +273,7 @@ describe('react-native-storage: basic function', () => {
});
});
pit('removes all data for key correctly' + `(${storageKey})`, () => {
test('removes all data for key correctly' + `(${storageKey})`, () => {
let key = 'testKey' + Math.random(),
testIds = [Math.random(), Math.random(), Math.random()],
testDatas = [Math.random(), Math.random(), Math.random()];
@@ -282,7 +282,7 @@ describe('react-native-storage: basic function', () => {
testIds.map((id, i) => storage.save({
key,
id,
rawData: testDatas[i]
data: testDatas[i]
}))
)
.then(() => {
@@ -303,16 +303,16 @@ describe('react-native-storage: basic function', () => {
});
});
pit('loads ids by key correctly' + `(${storageKey})`, () => {
test('loads ids by key correctly' + `(${storageKey})`, () => {
let key = 'testKey' + Math.random(),
testIds = [Math.random(), Math.random(), Math.random()],
rawData = 'testData' + Math.random();
data = 'testData' + Math.random();
let ret = [];
let tasks = testIds.map(id =>
storage.save({
key,
id,
rawData
data
})
);
return Promise.all(tasks).then(() => {
Oops, something went wrong.

0 comments on commit ffcff48

Please sign in to comment.