y-protocols
Advanced tools
Comparing version 0.2.3 to 1.0.0
@@ -10,2 +10,3 @@ /** | ||
import { Observable } from 'lib0/observable.js' | ||
import * as f from 'lib0/function.js' | ||
import * as Y from 'yjs' // eslint-disable-line | ||
@@ -95,2 +96,3 @@ | ||
const clock = currLocalMeta === undefined ? 0 : currLocalMeta.clock + 1 | ||
const prevState = this.states.get(clientID) | ||
if (state === null) { | ||
@@ -107,11 +109,20 @@ this.states.delete(clientID) | ||
const updated = [] | ||
const filteredUpdated = [] | ||
const removed = [] | ||
if (state === null) { | ||
removed.push(clientID) | ||
} else if (currLocalMeta === undefined) { | ||
added.push(clientID) | ||
} else if (prevState == null) { | ||
if (state != null) { | ||
added.push(clientID) | ||
} | ||
} else { | ||
updated.push(clientID) | ||
if (!f.equalityDeep(prevState, state)) { | ||
filteredUpdated.push(clientID) | ||
} | ||
} | ||
this.emit('change', [{ added, updated, removed }, 'local']) | ||
if (added.length > 0 || filteredUpdated.length > 0 || removed.length > 0) { | ||
this.emit('change', [{ added, updated: filteredUpdated, removed }, 'local']) | ||
} | ||
this.emit('update', [{ added, updated, removed }, 'local']) | ||
} | ||
@@ -163,2 +174,3 @@ /** | ||
awareness.emit('change', [{ added: [], updated: [], removed }, origin]) | ||
awareness.emit('update', [{ added: [], updated: [], removed }, origin]) | ||
} | ||
@@ -197,2 +209,3 @@ } | ||
const updated = [] | ||
const filteredUpdated = [] | ||
const removed = [] | ||
@@ -205,2 +218,3 @@ const len = decoding.readVarUint(decoder) | ||
const clientMeta = awareness.meta.get(clientID) | ||
const prevState = awareness.states.get(clientID) | ||
const currClock = clientMeta === undefined ? 0 : clientMeta.clock | ||
@@ -229,2 +243,5 @@ if (currClock < clock || (currClock === clock && state === null && awareness.states.has(clientID))) { | ||
} else if (state !== null) { | ||
if (!f.equalityDeep(state, prevState)) { | ||
filteredUpdated.push(clientID) | ||
} | ||
updated.push(clientID) | ||
@@ -234,4 +251,9 @@ } | ||
} | ||
if (added.length > 0 || filteredUpdated.length > 0 || removed.length > 0) { | ||
awareness.emit('change', [{ | ||
added, updated: filteredUpdated, removed | ||
}, origin]) | ||
} | ||
if (added.length > 0 || updated.length > 0 || removed.length > 0) { | ||
awareness.emit('change', [{ | ||
awareness.emit('update', [{ | ||
added, updated, removed | ||
@@ -238,0 +260,0 @@ }, origin]) |
{ | ||
"name": "y-protocols", | ||
"version": "0.2.3", | ||
"version": "1.0.0", | ||
"description": "Yjs encoding protocols", | ||
"type": "module", | ||
"funding": { | ||
"type": "GitHub Sponsors ❤", | ||
"url": "https://github.com/sponsors/dmonad" | ||
}, | ||
"files": [ | ||
@@ -15,5 +19,6 @@ "dist/*", | ||
"dist": "rm -rf dist && rollup -c", | ||
"test": "npm run lint", | ||
"test": "npm run lint && npm run dist && node dist/test.cjs", | ||
"lint": "standard && tsc", | ||
"types": "tsc --outDir .", | ||
"debug": "rollup -c && concurrently 'rollup -wc' 'http-server -o test.html'", | ||
"preversion": "npm run dist && npm run test && npm run types", | ||
@@ -42,7 +47,6 @@ "postpublish": "npm run clean" | ||
"dependencies": { | ||
"lib0": "^0.2.20" | ||
"lib0": "^0.2.28" | ||
}, | ||
"devDependencies": { | ||
"rollup": "^1.1.2", | ||
"rollup-cli": "^1.0.9", | ||
"rollup": "^1.29.0", | ||
"standard": "^12.0.1", | ||
@@ -49,0 +53,0 @@ "typescript": "^3.8.3", |
@@ -48,3 +48,3 @@ # Yjs Protocols | ||
<dd> | ||
Only update a single field on the local awareness object. Does not do | ||
Only update a single field on the local awareness object. Does not do | ||
anything if the local state is not set. | ||
@@ -62,4 +62,12 @@ </dd> | ||
<dd> | ||
Listen to remote and local changes on the awareness instance. | ||
Listen to remote and local state changes on the awareness instance. | ||
</dd> | ||
<b><code> | ||
on('update', ({ added: Array<number>, updated: Array<number> | ||
removed: Array<number> }, [transactionOrigin:any]) => ..) | ||
</code></b> | ||
<dd> | ||
Listen to remote and local awareness changes on the awareness instance. | ||
This event is called even when the awarenes state does not change. | ||
</dd> | ||
</dl> | ||
@@ -66,0 +74,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
779273
4
25
8163
0
76
1
Updatedlib0@^0.2.28