@qrvey/utils 1.13.0-15 → 1.13.0-16
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.
|
@@ -11,13 +11,15 @@ interface QrveyCacheStore<T> {
|
|
|
11
11
|
}
|
|
12
12
|
export declare abstract class QrveyCacheManager<TStoreState extends QvCacheStoreProperties, TConfig> {
|
|
13
13
|
protected stores: Map<string, QrveyCacheStore<TStoreState> | Promise<QrveyCacheStore<TStoreState>>>;
|
|
14
|
+
operationLocks: Map<any, any>;
|
|
14
15
|
protected abstract getConfigEntityId(): keyof TConfig;
|
|
15
16
|
protected abstract buildStoreId(config: TConfig): string;
|
|
16
17
|
protected abstract fetchDataAndUpdateStore(state: TStoreState, config: TConfig): Promise<void>;
|
|
17
18
|
protected createStore(_initialState?: Partial<TStoreState>): Promise<QrveyCacheStore<TStoreState>>;
|
|
18
19
|
getStoreFromPromise(config: TConfig, id: string): Promise<QrveyCacheStore<TStoreState>>;
|
|
19
20
|
private getCreatedStore;
|
|
20
|
-
|
|
21
|
+
private initializeStore;
|
|
22
|
+
getStore(config: TConfig): Promise<QrveyCacheStore<TStoreState>>;
|
|
21
23
|
getMultipleStores(config: TConfig, ids: string[]): Promise<QrveyCacheStore<TStoreState>[]>;
|
|
22
24
|
setStoresFromData(stores: {
|
|
23
25
|
storeId: string;
|
|
@@ -11,6 +11,7 @@ import { createStore } from "@stencil/store";
|
|
|
11
11
|
export class QrveyCacheManager {
|
|
12
12
|
constructor() {
|
|
13
13
|
this.stores = new Map();
|
|
14
|
+
this.operationLocks = new Map();
|
|
14
15
|
}
|
|
15
16
|
createStore(_initialState) {
|
|
16
17
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -40,30 +41,35 @@ export class QrveyCacheManager {
|
|
|
40
41
|
return this.stores.get(storeId);
|
|
41
42
|
});
|
|
42
43
|
}
|
|
44
|
+
initializeStore(config, storeId) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const newStore = yield this.createStore();
|
|
47
|
+
yield this.fetchDataAndUpdateStore(newStore.state, config);
|
|
48
|
+
this.stores.set(storeId, newStore);
|
|
49
|
+
return newStore;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
43
52
|
getStore(config) {
|
|
44
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
45
54
|
const storeId = this.buildStoreId(config);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return existingStore instanceof Promise
|
|
49
|
-
? yield existingStore
|
|
50
|
-
: existingStore;
|
|
55
|
+
while (this.operationLocks.has(storeId)) {
|
|
56
|
+
yield this.operationLocks.get(storeId);
|
|
51
57
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return
|
|
58
|
+
let store = this.stores.get(storeId);
|
|
59
|
+
if (!store) {
|
|
60
|
+
let resolveLock;
|
|
61
|
+
const lockPromise = new Promise((resolve) => (resolveLock = resolve));
|
|
62
|
+
this.operationLocks.set(storeId, lockPromise);
|
|
63
|
+
try {
|
|
64
|
+
store = yield this.initializeStore(config, storeId);
|
|
65
|
+
this.stores.set(storeId, store);
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
resolveLock();
|
|
69
|
+
this.operationLocks.delete(storeId);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return store;
|
|
67
73
|
});
|
|
68
74
|
}
|
|
69
75
|
getMultipleStores(config, ids) {
|
|
@@ -11,13 +11,15 @@ interface QrveyCacheStore<T> {
|
|
|
11
11
|
}
|
|
12
12
|
export declare abstract class QrveyCacheManager<TStoreState extends QvCacheStoreProperties, TConfig> {
|
|
13
13
|
protected stores: Map<string, QrveyCacheStore<TStoreState> | Promise<QrveyCacheStore<TStoreState>>>;
|
|
14
|
+
operationLocks: Map<any, any>;
|
|
14
15
|
protected abstract getConfigEntityId(): keyof TConfig;
|
|
15
16
|
protected abstract buildStoreId(config: TConfig): string;
|
|
16
17
|
protected abstract fetchDataAndUpdateStore(state: TStoreState, config: TConfig): Promise<void>;
|
|
17
18
|
protected createStore(_initialState?: Partial<TStoreState>): Promise<QrveyCacheStore<TStoreState>>;
|
|
18
19
|
getStoreFromPromise(config: TConfig, id: string): Promise<QrveyCacheStore<TStoreState>>;
|
|
19
20
|
private getCreatedStore;
|
|
20
|
-
|
|
21
|
+
private initializeStore;
|
|
22
|
+
getStore(config: TConfig): Promise<QrveyCacheStore<TStoreState>>;
|
|
21
23
|
getMultipleStores(config: TConfig, ids: string[]): Promise<QrveyCacheStore<TStoreState>[]>;
|
|
22
24
|
setStoresFromData(stores: {
|
|
23
25
|
storeId: string;
|
|
@@ -14,6 +14,7 @@ const store_1 = require("@stencil/store");
|
|
|
14
14
|
class QrveyCacheManager {
|
|
15
15
|
constructor() {
|
|
16
16
|
this.stores = new Map();
|
|
17
|
+
this.operationLocks = new Map();
|
|
17
18
|
}
|
|
18
19
|
createStore(_initialState) {
|
|
19
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -43,30 +44,35 @@ class QrveyCacheManager {
|
|
|
43
44
|
return this.stores.get(storeId);
|
|
44
45
|
});
|
|
45
46
|
}
|
|
47
|
+
initializeStore(config, storeId) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const newStore = yield this.createStore();
|
|
50
|
+
yield this.fetchDataAndUpdateStore(newStore.state, config);
|
|
51
|
+
this.stores.set(storeId, newStore);
|
|
52
|
+
return newStore;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
46
55
|
getStore(config) {
|
|
47
56
|
return __awaiter(this, void 0, void 0, function* () {
|
|
48
57
|
const storeId = this.buildStoreId(config);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return existingStore instanceof Promise
|
|
52
|
-
? yield existingStore
|
|
53
|
-
: existingStore;
|
|
58
|
+
while (this.operationLocks.has(storeId)) {
|
|
59
|
+
yield this.operationLocks.get(storeId);
|
|
54
60
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return
|
|
61
|
+
let store = this.stores.get(storeId);
|
|
62
|
+
if (!store) {
|
|
63
|
+
let resolveLock;
|
|
64
|
+
const lockPromise = new Promise((resolve) => (resolveLock = resolve));
|
|
65
|
+
this.operationLocks.set(storeId, lockPromise);
|
|
66
|
+
try {
|
|
67
|
+
store = yield this.initializeStore(config, storeId);
|
|
68
|
+
this.stores.set(storeId, store);
|
|
69
|
+
}
|
|
70
|
+
finally {
|
|
71
|
+
resolveLock();
|
|
72
|
+
this.operationLocks.delete(storeId);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return store;
|
|
70
76
|
});
|
|
71
77
|
}
|
|
72
78
|
getMultipleStores(config, ids) {
|