@cocreate/crdt
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -0,1 +1,9 @@ | ||
## [1.7.1](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.7.0...v1.7.1) (2021-11-01) | ||
### Bug Fixes | ||
* await getText in replaceText ([41c219c](https://github.com/CoCreate-app/CoCreate-crdt/commit/41c219cb79f5e416661c73b3b62862e0e92bf767)) | ||
* startTimer was needed per each typeName and a flag for replaceText to skip timer all together ([20e74dc](https://github.com/CoCreate-app/CoCreate-crdt/commit/20e74dcef89ca5f6c6e6ec4b01c4d9e2a3e47ad6)) | ||
# [1.7.0](https://github.com/CoCreate-app/CoCreate-crdt/compare/v1.6.1...v1.7.0) (2021-10-30) | ||
@@ -2,0 +10,0 @@ |
{ | ||
"name": "@cocreate/crdt", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "CoCreate crdt", | ||
@@ -5,0 +5,0 @@ "author": "CoCreate LLC", |
@@ -98,2 +98,3 @@ /*globals config, atob, btoa, localStorage, CustomEvent*/ | ||
info.value = string; | ||
info.start = 0; | ||
insertChange(info); | ||
@@ -104,18 +105,12 @@ } | ||
let isTimerActive; | ||
let timer; | ||
function startTimer() { | ||
isTimerActive = true; | ||
restartTimer(); | ||
timer = setTimeout(() => { | ||
isTimerActive = false; | ||
var timeouts = {}; | ||
function startTimer(name, timerName) { | ||
name.set('isTimerActive', true); | ||
clearTimeout(timeouts[timerName]); | ||
timeouts[timerName] = setTimeout(() => { | ||
name.set('isTimerActive', false); | ||
}, 500); | ||
} | ||
function restartTimer() { | ||
clearTimeout(timer); | ||
} | ||
function insertChange(info, broadcast) { | ||
function insertChange(info, broadcast, flag) { | ||
// console.log('crdtInsert', info) | ||
@@ -143,2 +138,3 @@ let docName = generateDocName(info); | ||
let changeLog = name.get('changeLog'); | ||
let isTimerActive = name.get('isTimerActive') | ||
@@ -149,17 +145,18 @@ let lastChange = changeLog[changeLog.length - 1]; | ||
} | ||
if (lastChange && change.value.length == 1) { | ||
if (isTimerActive || change.start == lastChange.start){ | ||
startTimer(); | ||
change.start = lastChange.start + lastChange.value.length; | ||
info.start = change.start; | ||
if (flag != 'replace') { | ||
if (lastChange && change.value.length == 1) { | ||
if (isTimerActive || change.start == lastChange.start){ | ||
startTimer(name, `${docName}${typeName}`); | ||
change.start = lastChange.start + lastChange.value.length; | ||
info.start = change.start; | ||
} | ||
} | ||
} | ||
if (lastChange && change.length == 1) { | ||
if (isTimerActive || change.start == lastChange.start){ | ||
startTimer(); | ||
change.start = lastChange.start - lastChange.length; | ||
info.start = change.start; | ||
if (lastChange && change.length == 1) { | ||
if (isTimerActive || change.start == lastChange.start){ | ||
startTimer(name, `${docName}${typeName}`); | ||
change.start = lastChange.start - lastChange.length; | ||
info.start = change.start; | ||
} | ||
} | ||
} | ||
changeLog.push(change); | ||
@@ -277,4 +274,9 @@ let string = name.get('text') || ''; | ||
if (doc) { | ||
let oldValue = getText(info); | ||
updateText({ ...info, start: 0, length: oldValue.length, crud: false }); | ||
let oldValue = await getText(info); | ||
if (oldValue) | ||
info.length = oldValue.length; | ||
else | ||
info.length = 0; | ||
info.start = 0; | ||
updateText(info, 'replace'); | ||
} | ||
@@ -298,3 +300,3 @@ } | ||
*/ | ||
async function updateText(info) { | ||
async function updateText(info, flag) { | ||
let broadcast = true; | ||
@@ -304,3 +306,3 @@ let doc = await getDoc(info); | ||
insertChange(info, broadcast); | ||
insertChange(info, broadcast, flag); | ||
@@ -307,0 +309,0 @@ if (info.crud != 'false') { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
97155
512