Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b3693aff3 | ||
|
|
f75f47646b | ||
|
|
64044123e3 | ||
|
|
a286162ace | ||
|
|
f739f3b5d7 | ||
|
|
f2052f95f8 | ||
|
|
81324dc7d4 | ||
|
|
6599cb20b4 |
@@ -2,7 +2,7 @@
|
||||
<html>
|
||||
<body>
|
||||
<textarea style="width:80%;" rows=40 id="textfield" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
|
||||
<script src="../bower_components/yjs/y.js"></script>
|
||||
<script src="../bower_components/yjs/y.es6"></script>
|
||||
<script src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -49,7 +49,7 @@ Install yjs and its modules with [bower](http://bower.io/), or with [npm](https:
|
||||
|
||||
### Bower
|
||||
```
|
||||
bower install yjs
|
||||
bower install yjs --save
|
||||
```
|
||||
Then you include the libraries directly from the installation folder.
|
||||
```
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "yjs",
|
||||
"version": "0.8.19",
|
||||
"version": "0.8.28",
|
||||
"homepage": "y-js.org",
|
||||
"authors": [
|
||||
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
|
||||
|
||||
53
y.es6
53
y.es6
@@ -52,6 +52,7 @@ module.exports = function (Y/* :any */) {
|
||||
this.broadcastedHB = false
|
||||
this.syncStep2 = Promise.resolve()
|
||||
this.broadcastOpBuffer = []
|
||||
this.protocolVersion = 8
|
||||
}
|
||||
reconnect () {
|
||||
}
|
||||
@@ -208,6 +209,18 @@ module.exports = function (Y/* :any */) {
|
||||
if (this.debug) {
|
||||
console.log(`receive ${sender} -> ${this.userId}: ${message.type}`, JSON.parse(JSON.stringify(message))) // eslint-disable-line
|
||||
}
|
||||
if (message.protocolVersion != null && message.protocolVersion !== this.protocolVersion) {
|
||||
console.error(
|
||||
`You tried to sync with a yjs instance that has a different protocol version
|
||||
(You: ${this.protocolVersion}, Client: ${message.protocolVersion}).
|
||||
The sync was stopped. You need to upgrade your dependencies (especially Yjs & the Connector)!
|
||||
`)
|
||||
this.send(sender, {
|
||||
type: 'sync stop',
|
||||
protocolVersion: this.protocolVersion
|
||||
})
|
||||
return
|
||||
}
|
||||
if (message.type === 'sync step 1') {
|
||||
// TODO: make transaction, stream the ops
|
||||
let conn = this
|
||||
@@ -718,9 +731,17 @@ module.exports = function (Y /* :any */) {
|
||||
this.gc2 = this.gc2.filter(filter)
|
||||
delete op.gc
|
||||
}
|
||||
destroy () {
|
||||
* destroy () {
|
||||
clearInterval(this.gcInterval)
|
||||
this.gcInterval = null
|
||||
for (var key in this.initializedTypes) {
|
||||
var type = this.initializedTypes[key]
|
||||
if (type._destroy != null) {
|
||||
type._destroy()
|
||||
} else {
|
||||
console.error('The type you included does not provide destroy functionality, it will remain in memory (updating your packages will help).')
|
||||
}
|
||||
}
|
||||
}
|
||||
setUserId (userId) {
|
||||
if (!this.userIdPromise.inProgress) {
|
||||
@@ -775,8 +796,8 @@ module.exports = function (Y /* :any */) {
|
||||
missing: ids.length
|
||||
}
|
||||
|
||||
for (let key in ids) {
|
||||
let id = ids[key]
|
||||
for (let i = 0; i < ids.length; i++) {
|
||||
let id = ids[i]
|
||||
let sid = JSON.stringify(id)
|
||||
let l = this.listenersById[sid]
|
||||
if (l == null) {
|
||||
@@ -819,8 +840,8 @@ module.exports = function (Y /* :any */) {
|
||||
if (op == null) {
|
||||
store.listenersById[sid] = l
|
||||
} else {
|
||||
for (let key in l) {
|
||||
let listener = l[key]
|
||||
for (let i = 0; i < l.length; i++) {
|
||||
let listener = l[i]
|
||||
let o = listener.op
|
||||
if (--listener.missing === 0) {
|
||||
yield* store.tryExecute.call(this, o)
|
||||
@@ -2252,6 +2273,12 @@ module.exports = function (Y /* : any*/) {
|
||||
this.onevent = onevent
|
||||
this.eventListeners = []
|
||||
}
|
||||
destroy () {
|
||||
this.waiting = null
|
||||
this.awaiting = null
|
||||
this.onevent = null
|
||||
this.eventListeners = null
|
||||
}
|
||||
/*
|
||||
Call this when a new operation arrives. It will be executed right away if
|
||||
there are no waiting operations, that you prematurely executed
|
||||
@@ -2697,6 +2724,7 @@ class YConfig {
|
||||
db: Y.AbstractDatabase;
|
||||
connector: Y.AbstractConnector;
|
||||
share: {[key: string]: any};
|
||||
options: Object;
|
||||
*/
|
||||
constructor (opts, callback) {
|
||||
this.options = opts
|
||||
@@ -2734,10 +2762,17 @@ class YConfig {
|
||||
return this.connector.reconnect()
|
||||
}
|
||||
destroy () {
|
||||
this.disconnect()
|
||||
this.db.destroy()
|
||||
this.connector = null
|
||||
this.db = null
|
||||
if (this.connector.destroy != null) {
|
||||
this.connector.destroy()
|
||||
} else {
|
||||
this.connector.disconnect()
|
||||
}
|
||||
var self = this
|
||||
this.db.requestTransaction(function * () {
|
||||
yield* self.db.destroy()
|
||||
self.connector = null
|
||||
self.db = null
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user