@cocreate/crdt 1.9.2 → 1.9.6

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,31 @@
1
+ ## [1.9.6](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.9.5...v1.9.6) (2022-02-10)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * bump dependencies ([138f512](https://github.com/CoCreate-app/CoCreate-crdt/commit/138f512c71cc486762bcc291990437006b94af6a))
7
+
8
+ ## [1.9.5](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.9.4...v1.9.5) (2022-02-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * value duplication resolved ([8894449](https://github.com/CoCreate-app/CoCreate-crdt/commit/8894449cda528249a3f7731490251b07db2a0a61))
14
+
15
+ ## [1.9.4](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.9.3...v1.9.4) (2022-02-07)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * bump dependency versions ([502da81](https://github.com/CoCreate-app/CoCreate-crdt/commit/502da8198e52076bef6132525a17c6b42314fc0c))
21
+
22
+ ## [1.9.3](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.9.2...v1.9.3) (2022-02-07)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * checkDb if condition was was true even if string was not empty. replaced == with === ([ca27e77](https://github.com/CoCreate-app/CoCreate-crdt/commit/ca27e770b2ebbabb1c2a5763e7c1205987731662))
28
+
1
29
  ## [1.9.2](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.9.1...v1.9.2) (2022-02-03)
2
30
 
3
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/crdt",
3
- "version": "1.9.2",
3
+ "version": "1.9.6",
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/actions": "^1.3.28",
47
- "@cocreate/crud-client": "^1.4.43",
48
- "@cocreate/message-client": "^1.1.60",
49
- "@cocreate/utils": "^1.5.0"
46
+ "@cocreate/actions": "^1.3.31",
47
+ "@cocreate/crud-client": "^1.4.46",
48
+ "@cocreate/message-client": "^1.1.63",
49
+ "@cocreate/utils": "^1.6.3"
50
50
  }
51
51
  }
package/src/index.js CHANGED
@@ -6,7 +6,8 @@ import action from '@cocreate/actions';
6
6
 
7
7
  const docs = new Map();
8
8
  const clientId = config.clientId || window.CoCreateSockets.clientId || uuid.generate(12);
9
-
9
+ const checkedDb = new Map();
10
+ const isInit = new Map();
10
11
 
11
12
  function init(info){
12
13
  getText(info).then(value => {
@@ -21,20 +22,23 @@ async function getDoc(info) {
21
22
  try {
22
23
  let docName = generateDocName(info);
23
24
  let typeName = info.name;
24
-
25
- if (!docs.has(docName)) {
25
+ let doc = docs.get(docName);
26
+
27
+ if (!doc) {
26
28
  let docNameMap = new Map();
27
29
  docs.set(docName, docNameMap);
30
+ doc = docs.get(docName);
28
31
  }
29
32
 
30
- if (!docs.get(docName).has(typeName)) {
33
+ let type = doc.get(typeName)
34
+ if (!type) {
31
35
  let typeNameMap = new Map();
32
- docs.get(docName).set(typeName, typeNameMap);
36
+ doc.set(typeName, typeNameMap);
37
+ type = doc.get(typeName)
33
38
  }
34
-
35
- if (!docs.get(docName).get(typeName).has('changeLog')) {
39
+ if (!type.has('changeLog')) {
36
40
  let changeLog = [];
37
-
41
+
38
42
  if (info.read != 'false') {
39
43
  let response = await crud.readDocumentList({
40
44
  collection: "crdt-transactions",
@@ -49,11 +53,12 @@ async function getDoc(info) {
49
53
  if (response.data.length && response.data[0][typeName]) {
50
54
  changeLog = response.data[0][typeName];
51
55
  }
52
- docs.get(docName).get(typeName).set('changeLog', changeLog);
56
+ type.set('changeLog', changeLog);
53
57
  await generateText(info, true);
54
58
  }
59
+
55
60
  }
56
- else if (!docs.get(docName).get(typeName).has('text')){
61
+ else if (!type.has('text')){
57
62
  await generateText(info, false);
58
63
  }
59
64
  return true;
@@ -75,7 +80,7 @@ async function generateText(info, flag) {
75
80
  for (let change of changeLog) {
76
81
  string = string.customSplice(change.start, change.length, change.value);
77
82
  }
78
- if (string == '' && info.read != 'false'){
83
+ if (string === '' && info.read !== 'false'){
79
84
  string = await checkDb(info, flag);
80
85
  }
81
86
  name.set('text', string);
@@ -88,7 +93,9 @@ async function generateText(info, flag) {
88
93
 
89
94
  async function checkDb(info, flag) {
90
95
  let { collection, document_id, name } = info;
91
- let response = await crud.readDocument({ collection, document_id, name })
96
+ if (checkedDb.get(`${collection}${document_id}${name}`)) return;
97
+ checkedDb.set(`${collection}${document_id}${name}`, true);
98
+ let response = await crud.readDocument({ collection, document_id, name });
92
99
  let string = response.data[name];
93
100
  if (string && flag != false) {
94
101
  info.value = string;
@@ -233,8 +240,6 @@ async function getText(info) {
233
240
  let doc = await getDoc(info);
234
241
  if (doc) {
235
242
  let value = docs.get(docName).get(typeName).get('text')
236
- if (!value)
237
- console.log(value)
238
243
  return value;
239
244
  }
240
245
  else {