Compare commits

...

3 Commits

Author SHA1 Message Date
Kevin Jahns
b32c2e4ed6 publish 0.7 - with (hopefully) stable API 2015-12-09 10:10:43 +01:00
Kevin Jahns
96f8f77dc4 update 2015-12-03 18:02:37 +01:00
Kevin Jahns
08f0702fcd update port 2015-12-02 20:04:11 +01:00
9 changed files with 79 additions and 5013 deletions

View File

@@ -17,7 +17,7 @@
</g>
</svg>
<script src="../bower_components/yjs/y.es6"></script>
<script src="../bower_components/yjs/y.js"></script>
<script src="../bower_components/d3/d3.js"></script>
<script src="./index.js"></script>
</body>

View File

@@ -7,10 +7,10 @@ Y({
name: 'memory'
},
connector: {
url: 'http://127.0.0.1:1234',
name: 'websockets-client',
room: 'Puzzle-example2',
debug: true
room: 'Puzzle-example2'
// debug: true,
// url: 'http://127.0.0.1:2345'
},
sourceDir: '/bower_components',
share: {
@@ -43,7 +43,7 @@ Y({
var mouse = d3.mouse(this.parentNode)
var x = mouse[0] - origin.x
var y = mouse[1] - origin.y
piece.set('translation', {x, y})
piece.set('translation', {x: x, y: y})
})
var data = [y.share.piece1, y.share.piece2, y.share.piece3, y.share.piece4]

View File

@@ -3,7 +3,7 @@
<body>
<textarea style="width:80%;" rows=40 id="textfield"></textarea>
<script src="../bower_components/yjs/y.es6"></script>
<script src="../bower_components/yjs/y.js"></script>
<script src="./index.js"></script>
</body>
</html>

View File

@@ -8,6 +8,8 @@ Y({
connector: {
name: 'websockets-client',
room: 'Textarea-example'
// debug: true
// url: 'http://127.0.0.1:2345'
},
sourceDir: '/bower_components',
share: {

View File

@@ -1,6 +1,6 @@
{
"name": "yjs",
"version": "0.6.42",
"version": "0.7.0",
"homepage": "y-js.org",
"authors": [
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"

99
y.es6
View File

@@ -1162,6 +1162,14 @@ module.exports = function (Y/* :any */) {
id: this.os.getNextOpId()
}
*/
create: function (id) {
return {
start: null,
end: null,
struct: 'List',
id: id
}
},
encode: function (op) {
return {
struct: 'List',
@@ -1228,6 +1236,13 @@ module.exports = function (Y/* :any */) {
id: this.os.getNextOpId()
}
*/
create: function (id) {
return {
id: id,
map: {},
struct: 'Map'
}
},
encode: function (op) {
return {
struct: 'Map',
@@ -1363,6 +1378,14 @@ module.exports = function (Y/* :any */) {
}
return t
}
* createType (typedefinition) {
var structname = typedefinition.struct
var id = this.store.getNextOpId()
var op = Y.Struct[structname].create(id)
op.type = typedefinition.name
yield* this.applyCreatedOperations([op])
return yield* this.getType(id)
}
/*
Apply operations that this user created (no remote ones!)
* does not check for Struct.*.requiredOps()
@@ -1373,9 +1396,11 @@ module.exports = function (Y/* :any */) {
for (var i = 0; i < ops.length; i++) {
var op = ops[i]
yield* this.store.tryExecute.call(this, op)
send.push(Y.Struct[op.struct].encode(op))
if (op.id == null || op.id[0] !== '_') {
send.push(Y.Struct[op.struct].encode(op))
}
}
if (!this.store.y.connector.isDisconnected()) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
if (!this.store.y.connector.isDisconnected() && send.length > 0) { // TODO: && !this.store.forwardAppliedOperations (but then i don't send delete ops)
// is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcast({
type: 'update',
@@ -1814,7 +1839,7 @@ module.exports = function (Y/* :any */) {
}
* addOperation (op) {
yield* this.os.put(op)
if (!this.store.y.connector.isDisconnected() && this.store.forwardAppliedOperations) {
if (!this.store.y.connector.isDisconnected() && this.store.forwardAppliedOperations && op.id[0] !== '_') {
// is connected, and this is not going to be send in addOperation
this.store.y.connector.broadcast({
type: 'update',
@@ -1829,11 +1854,12 @@ module.exports = function (Y/* :any */) {
} else {
// need to generate this operation
if (this.store._nextUserId == null) {
var typename = id[1].split('_')[0]
this.store._nextUserId = id
yield* Y[typename].createType.call(this)
delete this.store._nextUserId
return yield* this.os.find(id)
var struct = id[1].split('_')[0]
// this.store._nextUserId = id
var op = Y.Struct[struct].create(id)
yield* this.setOperation(op)
// delete this.store._nextUserId
return op
} else {
// Can only generate one operation at a time
return null
@@ -2131,8 +2157,8 @@ module.exports = function (Y /* : any*/) {
A wrapper for the definition of a custom type.
Every custom type must have three properties:
* createType
- Defines the model of a newly created custom type and returns the type
* struct
- Structname of this type
* initType
- Given a model, creates a custom type
* class
@@ -2140,20 +2166,23 @@ module.exports = function (Y /* : any*/) {
*/
class CustomType { // eslint-disable-line
/* ::
createType: any;
struct: any;
initType: any;
class: Function;
name: String;
*/
constructor (def) {
if (def.createType == null ||
if (def.struct == null ||
def.initType == null ||
def.class == null
def.class == null ||
def.name == null
) {
throw new Error('Custom type was not initialized correctly!')
}
this.createType = def.createType
this.struct = def.struct
this.initType = def.initType
this.class = def.class
this.name = def.name
}
}
Y.utils.CustomType = CustomType
@@ -2223,30 +2252,26 @@ function requestModules (modules) {
// determine if this module was compiled for es5 or es6 (y.js vs. y.es6)
// if Insert.execute is a Function, then it isnt a generator..
// then load the es5(.js) files..
var extention = Y.Struct.Insert.execute.constructor === Function ? '.js' : '.es6'
var extention = typeof regeneratorRuntime !== 'undefined' ? '.js' : '.es6'
var promises = []
for (var i = 0; i < modules.length; i++) {
var modulename = 'y-' + modules[i].toLowerCase()
if (Y[modules[i]] == null) {
if (requiringModules[modules[i]] == null) {
try {
require(modulename)(Y)
} catch (e) {
// module does not exist
if (typeof window !== 'undefined') {
var imported = document.createElement('script')
imported.src = Y.sourceDir + '/' + modulename + '/' + modulename + extention
document.head.appendChild(imported)
// module does not exist
if (typeof window !== 'undefined' && window.Y !== 'undefined') {
var imported = document.createElement('script')
imported.src = Y.sourceDir + '/' + modulename + '/' + modulename + extention
document.head.appendChild(imported)
let requireModule = {}
requiringModules[modules[i]] = requireModule
requireModule.promise = new Promise(function (resolve) {
requireModule.resolve = resolve
})
promises.push(requireModule.promise)
} else {
throw e
}
let requireModule = {}
requiringModules[modules[i]] = requireModule
requireModule.promise = new Promise(function (resolve) {
requireModule.resolve = resolve
})
promises.push(requireModule.promise)
} else {
require(modulename)(Y)
}
} else {
promises.push(requiringModules[modules[i]].promise)
@@ -2317,7 +2342,15 @@ class YConfig {
this.db.requestTransaction(function * requestTransaction () {
// create shared object
for (var propertyname in opts.share) {
share[propertyname] = yield* this.getType(['_', opts.share[propertyname] + '_' + propertyname])
var typename = opts.share[propertyname]
var id = ['_', Y[typename].struct + '_' + propertyname]
var op = yield* this.getOperation(id)
if (op.type !== typename) {
// not already in the db
op.type = typename
yield* this.setOperation(op)
}
share[propertyname] = yield* this.getType(id)
}
setTimeout(callback, 0)
})

File diff suppressed because one or more lines are too long

4973
y.js

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long