Compare commits

...

7 Commits

Author SHA1 Message Date
Kevin Jahns
b4f06e8f62 v13.0.0-29 -- distribution files 2017-11-10 18:46:20 -08:00
Kevin Jahns
05cd1d0575 13.0.0-29 2017-11-10 18:46:10 -08:00
Kevin Jahns
4edc22bedb remove prematurely commited dom-filter update 2017-11-10 18:45:41 -08:00
Kevin Jahns
16f84c67d5 13.0.0-28 2017-11-10 18:41:39 -08:00
Kevin Jahns
290d3c8ffe support undefined as an attribute value 2017-11-10 18:41:10 -08:00
Kevin Jahns
c51e8b46c2 13.0.0-27 2017-11-10 12:55:05 -08:00
Kevin Jahns
0cda1630d2 fix path bugs 2017-11-10 12:54:33 -08:00
16 changed files with 24991 additions and 40 deletions

36
package-lock.json generated
View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-25", "version": "13.0.0-29",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
@@ -2808,14 +2808,6 @@
} }
} }
}, },
"string_decoder": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"requires": {
"safe-buffer": "5.0.1"
}
},
"string-width": { "string-width": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
@@ -2826,6 +2818,14 @@
"strip-ansi": "3.0.1" "strip-ansi": "3.0.1"
} }
}, },
"string_decoder": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"requires": {
"safe-buffer": "5.0.1"
}
},
"stringstream": { "stringstream": {
"version": "0.0.5", "version": "0.0.5",
"bundled": true, "bundled": true,
@@ -4868,15 +4868,6 @@
"duplexer": "0.1.1" "duplexer": "0.1.1"
} }
}, },
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"dev": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"string-width": { "string-width": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
@@ -4898,6 +4889,15 @@
"resolved": "https://registry.npmjs.org/string.prototype.codepointat/-/string.prototype.codepointat-0.2.0.tgz", "resolved": "https://registry.npmjs.org/string.prototype.codepointat/-/string.prototype.codepointat-0.2.0.tgz",
"integrity": "sha1-aybpvTr8qnvjtCabUm3huCAArHg=" "integrity": "sha1-aybpvTr8qnvjtCabUm3huCAArHg="
}, },
"string_decoder": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
"integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
"dev": true,
"requires": {
"safe-buffer": "5.1.1"
}
},
"strip-ansi": { "strip-ansi": {
"version": "3.0.1", "version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",

View File

@@ -1,6 +1,6 @@
{ {
"name": "yjs", "name": "yjs",
"version": "13.0.0-26", "version": "13.0.0-29",
"description": "A framework for real-time p2p shared editing on any data", "description": "A framework for real-time p2p shared editing on any data",
"main": "./y.node.js", "main": "./y.node.js",
"browser": "./y.js", "browser": "./y.js",

View File

@@ -20,7 +20,13 @@ export default class ItemJSON extends Item {
this._content = new Array(len) this._content = new Array(len)
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
const ctnt = decoder.readVarString() const ctnt = decoder.readVarString()
this._content[i] = JSON.parse(ctnt) let parsed
if (ctnt === 'undefined') {
parsed = undefined
} else {
parsed = JSON.parse(ctnt)
}
this._content[i] = parsed
} }
return missing return missing
} }
@@ -29,7 +35,14 @@ export default class ItemJSON extends Item {
let len = this._content.length let len = this._content.length
encoder.writeVarUint(len) encoder.writeVarUint(len)
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
encoder.writeVarString(JSON.stringify(this._content[i])) let encoded
let content = this._content[i]
if (content === undefined) {
encoded = 'undefined'
} else {
encoded = JSON.stringify(content)
}
encoder.writeVarString(encoded)
} }
} }
_logString () { _logString () {

View File

@@ -1,5 +1,6 @@
import Type from '../Struct/Type.js' import Type from '../Struct/Type.js'
import ItemJSON from '../Struct/ItemJSON.js' import ItemJSON from '../Struct/ItemJSON.js'
import ItemString from '../Struct/ItemString.js'
import { logID } from '../MessageHandler/messageToString.js' import { logID } from '../MessageHandler/messageToString.js'
import YEvent from '../Util/YEvent.js' import YEvent from '../Util/YEvent.js'
@@ -19,7 +20,11 @@ export default class YArray extends Type {
while (n !== null) { while (n !== null) {
if (!n._deleted) { if (!n._deleted) {
if (pos < n._length) { if (pos < n._length) {
return n._content[n._length - pos] if (n.constructor === ItemJSON || n.constructor === ItemString) {
return n._content[pos]
} else {
return n
}
} }
pos -= n._length pos -= n._length
} }

View File

@@ -255,7 +255,7 @@ export default class YXmlFragment extends YArray {
} }
}) })
for (let dom of diffChildren) { for (let dom of diffChildren) {
if (dom._yxml != null) { if (dom._yxml != null && dom._yxml !== false) {
applyChangesFromDom(dom) applyChangesFromDom(dom)
} }
} }

View File

@@ -136,6 +136,28 @@ export function applyChangesFromDom (dom) {
} }
export function reflectChangesOnDom (events) { export function reflectChangesOnDom (events) {
// Make sure that no filtered attributes are applied to the structure
// if they were, delete them
/*
events.forEach(event => {
const target = event.target
const keys = this._domFilter(target.nodeName, Array.from(event.keysChanged))
if (keys === null) {
target._delete()
} else {
const removeKeys = new Set() // is a copy of event.keysChanged
event.keysChanged.forEach(key => { removeKeys.add(key) })
keys.forEach(key => {
// remove all accepted keys from removeKeys
removeKeys.delete(key)
})
// remove the filtered attribute
removeKeys.forEach(key => {
target.removeAttribute(key)
})
}
})
*/
this._mutualExclude(() => { this._mutualExclude(() => {
events.forEach(event => { events.forEach(event => {
const yxml = event.target const yxml = event.target

View File

@@ -76,7 +76,6 @@ export default class UndoManager {
if (!this._undoing) { if (!this._undoing) {
let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null let lastUndoOp = this._undoBuffer.length > 0 ? this._undoBuffer[this._undoBuffer.length - 1] : null
if (lastUndoOp !== null && reverseOperation.created - lastUndoOp.created <= options.captureTimeout) { if (lastUndoOp !== null && reverseOperation.created - lastUndoOp.created <= options.captureTimeout) {
console.log('appending', lastUndoOp, reverseOperation)
lastUndoOp.created = reverseOperation.created lastUndoOp.created = reverseOperation.created
lastUndoOp.toState = reverseOperation.toState lastUndoOp.toState = reverseOperation.toState
reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs) reverseOperation.deletedStructs.forEach(lastUndoOp.deletedStructs.add, lastUndoOp.deletedStructs)
@@ -93,7 +92,6 @@ export default class UndoManager {
}) })
} }
undo () { undo () {
console.log('undoing')
this._undoing = true this._undoing = true
const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer) const performedUndo = applyReverseOperation(this.y, this._scope, this._undoBuffer)
this._undoing = false this._undoing = false

View File

@@ -8,15 +8,15 @@ export default class YEvent {
const path = [] const path = []
let type = this.target let type = this.target
const y = type._y const y = type._y
while (type._parent !== this._currentTarget && type._parent !== y) { while (type !== this.currentTarget && type !== y) {
let parent = type._parent let parent = type._parent
if (type._parentSub !== null) { if (type._parentSub !== null) {
path.push(type._parentSub) path.unshift(type._parentSub)
} else { } else {
// parent is array-ish // parent is array-ish
for (let [i, child] of parent) { for (let [i, child] of parent) {
if (child === type) { if (child === type) {
path.push(i) path.unshift(i)
break break
} }
} }

View File

@@ -41,6 +41,8 @@ test('basic map tests', async function map0 (t) {
test('Basic get&set of Map property (converge via sync)', async function map1 (t) { test('Basic get&set of Map property (converge via sync)', async function map1 (t) {
let { users, map0 } = await initArrays(t, { users: 2 }) let { users, map0 } = await initArrays(t, { users: 2 })
map0.set('stuff', 'stuffy') map0.set('stuff', 'stuffy')
map0.set('undefined', undefined)
map0.set('null', null)
t.compare(map0.get('stuff'), 'stuffy') t.compare(map0.get('stuff'), 'stuffy')
await flushAll(t, users) await flushAll(t, users)
@@ -48,6 +50,8 @@ test('Basic get&set of Map property (converge via sync)', async function map1 (t
for (let user of users) { for (let user of users) {
var u = user.get('map', Y.Map) var u = user.get('map', Y.Map)
t.compare(u.get('stuff'), 'stuffy') t.compare(u.get('stuff'), 'stuffy')
t.assert(u.get('undefined') === undefined, 'undefined')
t.compare(u.get('null'), null, 'null')
} }
await compareUsers(t, users) await compareUsers(t, users)
}) })
@@ -172,31 +176,36 @@ test('observePath properties', async function map10 (t) {
}) })
*/ */
/* TODO: reimplement observeDeep
test('observe deep properties', async function map11 (t) { test('observe deep properties', async function map11 (t) {
let { users, map1, map2, map3 } = await initArrays(t, { users: 4 }) let { users, map1, map2, map3 } = await initArrays(t, { users: 4 })
var _map1 = map1.set('map', new Y.Map()) var _map1 = map1.set('map', new Y.Map())
var calls = 0 var calls = 0
var dmapid var dmapid
_map1.observe(function (event) { map1.observeDeep(function (events) {
calls++ events.forEach(event => {
t.compare(event.name, 'deepmap') calls++
dmapid = event.target.opContents.deepmap t.assert(event.keysChanged.has('deepmap'))
t.assert(event.path.length === 1)
t.assert(event.path[0] === 'map')
dmapid = event.target.get('deepmap')._id
})
}) })
await flushAll(t, users) await flushAll(t, users)
await flushAll(t, users)
var _map3 = map3.get('map') var _map3 = map3.get('map')
_map3.set('deepmap', new Y.Map()) _map3.set('deepmap', new Y.Map())
await flushAll(t, users) await flushAll(t, users)
var _map2 = map2.get('map') var _map2 = map2.get('map')
_map2.set('deepmap', new Y.Map()) _map2.set('deepmap', new Y.Map())
await flushAll(t, users) await flushAll(t, users)
await flushAll(t, users)
var dmap1 = _map1.get('deepmap') var dmap1 = _map1.get('deepmap')
var dmap2 = _map2.get('deepmap') var dmap2 = _map2.get('deepmap')
var dmap3 = _map3.get('deepmap') var dmap3 = _map3.get('deepmap')
t.assert(calls > 0) t.assert(calls > 0)
t.compare(dmap1._model, dmap2._model) t.assert(dmap1._id.equals(dmap2._id))
t.compare(dmap1._model, dmap3._model) t.assert(dmap1._id.equals(dmap3._id))
t.compare(dmap1._model, dmapid) t.assert(dmap1._id.equals(dmapid))
await compareUsers(t, users) await compareUsers(t, users)
}) })
@@ -204,8 +213,10 @@ test('observes using observeDeep', async function map12 (t) {
let { users, map0 } = await initArrays(t, { users: 2 }) let { users, map0 } = await initArrays(t, { users: 2 })
var pathes = [] var pathes = []
var calls = 0 var calls = 0
map0.observeDeep(function (event) { map0.observeDeep(function (events) {
pathes.push(event.path) events.forEach(event => {
pathes.push(event.path)
})
calls++ calls++
}) })
map0.set('map', new Y.Map()) map0.set('map', new Y.Map())
@@ -215,7 +226,6 @@ test('observes using observeDeep', async function map12 (t) {
t.compare(pathes, [[], ['map'], ['map', 'array']]) t.compare(pathes, [[], ['map'], ['map', 'array']])
await compareUsers(t, users) await compareUsers(t, users)
}) })
*/
/* TODO: Test events in Y.Map /* TODO: Test events in Y.Map
function compareEvent (t, is, should) { function compareEvent (t, is, should) {

View File

@@ -187,7 +187,7 @@ export async function flushAll (t, users) {
if (users.length === 0) { if (users.length === 0) {
return return
} }
await wait(0) await wait(10)
if (users[0].connector.testRoom != null) { if (users[0].connector.testRoom != null) {
// use flushAll method specified in Test Connector // use flushAll method specified in Test Connector
await users[0].connector.testRoom.flushAll(users) await users[0].connector.testRoom.flushAll(users)

9
y.js Normal file

File diff suppressed because one or more lines are too long

1
y.js.map Normal file

File diff suppressed because one or more lines are too long

5567
y.node.js Normal file

File diff suppressed because it is too large Load Diff

1
y.node.js.map Normal file

File diff suppressed because one or more lines are too long

19324
y.test.js Normal file

File diff suppressed because one or more lines are too long

1
y.test.js.map Normal file

File diff suppressed because one or more lines are too long