@gudhub/core 1.0.38 → 1.0.39
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/GUDHUB/Processors/AppProcessor/AppProcessor.js +9 -8
- package/GUDHUB/Processors/ItemProcessor/ItemProcessor.js +2 -2
- package/GUDHUB/Utils/compare_items_lists_worker/compare_items_lists.worker.js +63 -38
- package/GUDHUB/Utils/merge_chunks/merge_chunks.js +1 -0
- package/Readme.md +537 -537
- package/fake_server/fake_server_data/app_16259.js +1152 -1152
- package/index.js +2 -2
- package/indexUMD.js +4 -4
- package/package.json +46 -45
- package/umd/library.min.js +14 -12
- package/umd/library.min.js.map +1 -1
|
@@ -205,7 +205,7 @@ export class AppProcessor {
|
|
|
205
205
|
return this.deletingAppFromStorage(app_id);
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
async getApp(app_id) {
|
|
208
|
+
async getApp(app_id, trash = false) {
|
|
209
209
|
if (!app_id) return null;
|
|
210
210
|
|
|
211
211
|
let app = this.getAppFromStorage(app_id);
|
|
@@ -242,7 +242,7 @@ export class AppProcessor {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
return app;
|
|
245
|
+
return trash ? app : {...app, items_list: app.items_list.filter(item => !item.trash)};
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
async updateApp(app) {
|
|
@@ -372,17 +372,18 @@ export class AppProcessor {
|
|
|
372
372
|
if (IS_WEB && this.activateSW) {
|
|
373
373
|
navigator.serviceWorker.addEventListener("message", async (event) => {
|
|
374
374
|
if (event.data.type === "refresh app") {
|
|
375
|
-
const app = this.
|
|
376
|
-
if (app
|
|
375
|
+
const app = await this.getApp(event.data.payload.app_id);
|
|
376
|
+
if (app) {
|
|
377
377
|
this.util.compareAppsItemsLists(
|
|
378
|
-
event.data.payload.items_list,
|
|
379
378
|
app.items_list,
|
|
380
|
-
(
|
|
381
|
-
|
|
379
|
+
event.data.payload.items_list.filter(item => !item.trash),
|
|
380
|
+
({ diff_fields_items, diff_fields_items_Ids, diff_items, newItems, deletedItems }) => {
|
|
381
|
+
if (diff_items.length || newItems.length || deletedItems.length) {
|
|
382
|
+
|
|
382
383
|
this.pipeService.emit(
|
|
383
384
|
"gh_items_update",
|
|
384
385
|
{ app_id: event.data.payload.app_id },
|
|
385
|
-
event.data.payload.items_list
|
|
386
|
+
event.data.payload.items_list.filter(item => !item.trash),
|
|
386
387
|
);
|
|
387
388
|
diff_items.forEach((item) =>
|
|
388
389
|
this.pipeService.emit(
|
|
@@ -122,9 +122,9 @@ export class ItemProcessor {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
async getItems(app_id, trash = false) {
|
|
125
|
-
const app = await this.appProcessor.getApp(app_id)
|
|
125
|
+
const app = await this.appProcessor.getApp(app_id, trash);
|
|
126
126
|
if(!app) return null;
|
|
127
|
-
return
|
|
127
|
+
return app.items_list;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
async addNewItems(app_id, itemsList) {
|
|
@@ -1,46 +1,71 @@
|
|
|
1
1
|
export function compare_items_lists_Worker() {
|
|
2
|
-
return `function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
return `function createList(items) {
|
|
3
|
+
return items.reduce(
|
|
4
|
+
(acc, item) => {
|
|
5
|
+
acc.list[item.item_id] = item;
|
|
6
|
+
acc.ids.push(item.item_id);
|
|
7
|
+
return acc;
|
|
8
|
+
},
|
|
9
|
+
{ ids: [], list: {} }
|
|
9
10
|
);
|
|
11
|
+
};
|
|
12
|
+
function compareItemsLists(oldItems, newItems) {
|
|
13
|
+
const { ids: oldIds, list: oldList } = createList(oldItems);
|
|
14
|
+
const { ids: newIds, list: newList } = createList(newItems);
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
16
|
+
const deletedItemsIds = oldIds.filter((id) => !newIds.includes(id));
|
|
17
|
+
const recentItemsIds = oldIds.filter((id) => !deletedItemsIds.includes(id));
|
|
18
|
+
const newItemsIds = newIds.filter((id) => !oldIds.includes(id));
|
|
19
|
+
|
|
20
|
+
const diff_fields_items = {};
|
|
21
|
+
const diff_fields_items_Ids = [];
|
|
22
|
+
|
|
23
|
+
recentItemsIds.forEach((id) => {
|
|
24
|
+
const newItem = newList[id];
|
|
25
|
+
const oldItem = oldList[id];
|
|
26
|
+
|
|
27
|
+
oldItem.fields.forEach((field1) => {
|
|
28
|
+
const sameField = newItem.fields.find(
|
|
29
|
+
(field2) => Number(field2.field_id) === Number(field1.field_id)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
if (!sameField) {
|
|
33
|
+
if (!diff_fields_items[newItem.item_id]) {
|
|
34
|
+
diff_fields_items[newItem.item_id] = [];
|
|
35
|
+
diff_fields_items_Ids.push(newItem.item_id);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return diff_fields_items[newItem.item_id].push(field1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (field1.field_value != sameField.field_value) {
|
|
42
|
+
if (!diff_fields_items[newItem.item_id]) {
|
|
43
|
+
diff_fields_items[newItem.item_id] = [];
|
|
44
|
+
diff_fields_items_Ids.push(newItem.item_id);
|
|
45
|
+
}
|
|
46
|
+
return diff_fields_items[newItem.item_id].push(field1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
39
49
|
});
|
|
40
|
-
});
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
return {
|
|
52
|
+
newItems: newItemsIds.reduce((acc, id) => {
|
|
53
|
+
acc.push(newList[id]);
|
|
54
|
+
return acc;
|
|
55
|
+
}, []),
|
|
56
|
+
deletedItems: deletedItemsIds.reduce((acc, id) => {
|
|
57
|
+
acc.push(oldList[id]);
|
|
58
|
+
return acc;
|
|
59
|
+
}, []),
|
|
60
|
+
diff_fields_items_Ids,
|
|
61
|
+
diff_fields_items,
|
|
62
|
+
diff_items: diff_fields_items_Ids.reduce((acc, id) => {
|
|
63
|
+
acc.push(oldList[id]);
|
|
64
|
+
return acc;
|
|
65
|
+
}, []),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
44
69
|
self.addEventListener("message", (event) => {
|
|
45
70
|
const { items_list1, items_list2 } = event.data;
|
|
46
71
|
|
|
@@ -5,6 +5,7 @@ export function mergeChunks(chunks) {
|
|
|
5
5
|
chunk.items_list.forEach((item) => {
|
|
6
6
|
const dstItem = result[item.item_id];
|
|
7
7
|
if (dstItem) {
|
|
8
|
+
dstItem.trash = item.trash;
|
|
8
9
|
return item.fields.forEach((srcField) => {
|
|
9
10
|
let isFieldNonExist = true;
|
|
10
11
|
dstItem.fields = dstItem.fields.map((dstField) => {
|