@cocreate/crdt 1.8.22 → 1.8.23

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.8.23](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.8.22...v1.8.23) (2021-11-26)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * getDocs will request generateText with changeLog true or false ([2309736](https://github.com/CoCreate-app/CoCreate-crdt/commit/230973632f96a8a65f1bea430e626a8a7e6223af))
7
+
1
8
  ## [1.8.22](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.8.21...v1.8.22) (2021-11-23)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crdt",
3
- "version": "1.8.22",
3
+ "version": "1.8.23",
4
4
  "description": "CoCreate crdt",
5
5
  "author": "CoCreate LLC",
6
6
  "license": "SEE LICENSE",
@@ -43,9 +43,9 @@
43
43
  "webpack-log": "^3.0.1"
44
44
  },
45
45
  "dependencies": {
46
- "@cocreate/action": "^1.3.17",
47
- "@cocreate/crud-client": "^1.4.33",
48
- "@cocreate/message-client": "^1.1.51",
49
- "@cocreate/utils": "^1.3.11"
46
+ "@cocreate/action": "^1.3.18",
47
+ "@cocreate/crud-client": "^1.4.34",
48
+ "@cocreate/message-client": "^1.1.52",
49
+ "@cocreate/utils": "^1.3.12"
50
50
  }
51
51
  }
package/src/index.js CHANGED
@@ -34,7 +34,6 @@ async function getDoc(info) {
34
34
 
35
35
  if (!docs.get(docName).get(typeName).has('changeLog')) {
36
36
  let changeLog = [];
37
- docs.get(docName).get(typeName).set('changeLog', changeLog);
38
37
 
39
38
  if (info.read != 'false') {
40
39
  let response = await crud.readDocumentList({
@@ -49,12 +48,13 @@ async function getDoc(info) {
49
48
  });
50
49
  if (response.data.length && response.data[0][typeName]) {
51
50
  changeLog = response.data[0][typeName];
52
- docs.get(docName).get(typeName).set('changeLog', changeLog);
53
51
  }
52
+ docs.get(docName).get(typeName).set('changeLog', changeLog);
53
+ await generateText(info, true);
54
54
  }
55
55
  }
56
- if (!docs.get(docName).get(typeName).has('text')){
57
- await generateText(info);
56
+ else if (!docs.get(docName).get(typeName).has('text')){
57
+ await generateText(info, false);
58
58
  }
59
59
  return true;
60
60
  }
@@ -67,7 +67,7 @@ String.prototype.customSplice = function (index, absIndex, string) {
67
67
  return this.slice(0, index) + string+ this.slice(index + Math.abs(absIndex));
68
68
  };
69
69
 
70
- async function generateText(info) {
70
+ async function generateText(info, flag) {
71
71
  try {
72
72
  let name = docs.get(`${info.collection}${info.document_id}`).get(info.name);
73
73
  let string = '';
@@ -75,9 +75,10 @@ async function generateText(info) {
75
75
  for (let change of changeLog) {
76
76
  string = string.customSplice(change.start, change.length, change.value);
77
77
  }
78
+ if (string == '' && info.read != 'false'){
79
+ string = await checkDb(info, flag);
80
+ }
78
81
  name.set('text', string);
79
- if (string == '' && info.read != 'false')
80
- await checkDb(info);
81
82
  return;
82
83
  }
83
84
  catch (e) {
@@ -85,18 +86,16 @@ async function generateText(info) {
85
86
  }
86
87
  }
87
88
 
88
- function checkDb(info) {
89
+ async function checkDb(info, flag) {
89
90
  let { collection, document_id, name } = info;
90
- crud.readDocument({ collection, document_id, name }).then(response => {
91
- if (!response) return;
92
- let string = response.data[name];
93
- if (string) {
94
- info.value = string;
95
- info.start = 0;
96
- insertChange(info);
97
- }
98
- return;
99
- });
91
+ let response = await crud.readDocument({ collection, document_id, name })
92
+ let string = response.data[name];
93
+ if (string && flag != false) {
94
+ info.value = string;
95
+ info.start = 0;
96
+ insertChange(info);
97
+ }
98
+ return string || '';
100
99
  }
101
100
 
102
101
  function insertChange(info, broadcast, flag) {
@@ -233,8 +232,13 @@ async function getText(info) {
233
232
  let doc = await getDoc(info);
234
233
  if (doc) {
235
234
  let value = docs.get(docName).get(typeName).get('text')
235
+ if (!value)
236
+ console.log(value)
236
237
  return value;
237
238
  }
239
+ else {
240
+ console.log('undefined')
241
+ }
238
242
  }
239
243
  catch (e) {
240
244
  console.error(e);