comes-storage 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.d.ts +3 -3
- package/build/index.js +16 -33
- package/build/local-storage.js +1 -1
- package/build/setup.d.ts +3 -0
- package/build/setup.js +36 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
export * from './setup';
|
|
2
|
+
export * from './local-storage';
|
|
3
|
+
export * from './storage.type';
|
package/build/index.js
CHANGED
|
@@ -1,36 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (!es)
|
|
8
|
-
es = comes_1.es;
|
|
9
|
-
if (!storage)
|
|
10
|
-
storage = new local_storage_1.LocalStorageStorage();
|
|
11
|
-
for (let event of events) {
|
|
12
|
-
const initialMainObj = lastData(storageName, storage, es);
|
|
13
|
-
const initialObj = (storageName === event ? initialMainObj : initialMainObj[event]) || null;
|
|
14
|
-
es.send(event, initialObj);
|
|
15
|
-
es.addInter(event, (id, data) => {
|
|
16
|
-
let obj = lastData(storageName, storage, es);
|
|
17
|
-
if (storageName === id)
|
|
18
|
-
obj = data;
|
|
19
|
-
else
|
|
20
|
-
obj[id] = data;
|
|
21
|
-
storage.save(storageName, obj);
|
|
22
|
-
return data;
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
exports.setupStorage = setupStorage;
|
|
27
|
-
const lastData = (storageName, storage, es) => {
|
|
28
|
-
let mainEntry = es.get(storageName);
|
|
29
|
-
let obj = mainEntry.last || {};
|
|
30
|
-
if (!mainEntry.date) {
|
|
31
|
-
obj = storage.load(storageName);
|
|
32
|
-
mainEntry.date = Date.now();
|
|
33
|
-
mainEntry.last = obj;
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
34
7
|
}
|
|
35
|
-
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
15
|
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./setup"), exports);
|
|
18
|
+
__exportStar(require("./local-storage"), exports);
|
|
19
|
+
__exportStar(require("./storage.type"), exports);
|
package/build/local-storage.js
CHANGED
package/build/setup.d.ts
ADDED
package/build/setup.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupStorage = void 0;
|
|
4
|
+
const comes_1 = require("comes");
|
|
5
|
+
const local_storage_1 = require("./local-storage");
|
|
6
|
+
const setupStorage = (storageName, events, storage, es) => {
|
|
7
|
+
if (!es)
|
|
8
|
+
es = comes_1.es;
|
|
9
|
+
if (!storage)
|
|
10
|
+
storage = new local_storage_1.LocalStorageStorage();
|
|
11
|
+
for (let event of events) {
|
|
12
|
+
const initialMainObj = lastData(storageName, storage, es);
|
|
13
|
+
const initialObj = (storageName === event ? initialMainObj : initialMainObj[event]) || null;
|
|
14
|
+
es.send(event, initialObj);
|
|
15
|
+
es.addInter(event, (id, data) => {
|
|
16
|
+
let obj = lastData(storageName, storage, es);
|
|
17
|
+
if (storageName === id)
|
|
18
|
+
obj = data;
|
|
19
|
+
else
|
|
20
|
+
obj[id] = data;
|
|
21
|
+
storage.save(storageName, obj);
|
|
22
|
+
return data;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
exports.setupStorage = setupStorage;
|
|
27
|
+
const lastData = (storageName, storage, es) => {
|
|
28
|
+
let mainEntry = es.get(storageName);
|
|
29
|
+
let obj = mainEntry.last || {};
|
|
30
|
+
if (!mainEntry.date) {
|
|
31
|
+
obj = storage.load(storageName);
|
|
32
|
+
mainEntry.date = Date.now();
|
|
33
|
+
mainEntry.last = obj;
|
|
34
|
+
}
|
|
35
|
+
return obj;
|
|
36
|
+
};
|