new build system

This commit is contained in:
Kevin Jahns
2015-09-11 18:35:32 +02:00
parent 4bfe484fc2
commit 82b3e50d49
24 changed files with 241 additions and 149 deletions

View File

@@ -1,4 +1,5 @@
/* global EventHandler, Y, CustomType, Struct */
/* global Y */
'use strict'
;(function () {
class YArray {
@@ -9,7 +10,7 @@
this.idArray = idArray
// Array of all the values
this.valArray = valArray
this.eventHandler = new EventHandler(ops => {
this.eventHandler = new Y.utils.EventHandler(ops => {
var userEvents = []
for (var i in ops) {
var op = ops[i]
@@ -112,7 +113,8 @@
eventHandler.awaitedLastInserts(ops.length)
})
}
delete (pos, length = 1) {
delete (pos, length) {
if (length == null) { length = 1 }
if (typeof length !== 'number') {
throw new Error('pos must be a number!')
}
@@ -162,7 +164,7 @@
}
}
Y.Array = new CustomType({
Y.Array = new Y.utils.CustomType({
class: YArray,
createType: function * YArrayCreator () {
var model = {
@@ -177,7 +179,7 @@
},
initType: function * YArrayInitializer (os, model) {
var valArray = []
var idArray = yield* Struct.List.map.call(this, model, function (c) {
var idArray = yield* Y.Struct.List.map.call(this, model, function (c) {
valArray.push(c.content)
return JSON.stringify(c.id)
})

View File

@@ -1,4 +1,4 @@
/* global createUsers, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, co, garbageCollectAllUsers */
/* global createUsers, wait, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, wrapCo, garbageCollectAllUsers */
/* eslint-env browser,jasmine */
var numberOfYArrayTests = 5
@@ -7,28 +7,30 @@ describe('Array Type', function () {
var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000
beforeEach(co.wrap(function * (done) {
beforeEach(wrapCo(function * (done) {
yield createUsers(this, 3)
y1 = (yconfig1 = this.users[0]).root
y2 = (yconfig2 = this.users[1]).root
y3 = (yconfig3 = this.users[2]).root
flushAll = this.users[0].connector.flushAll
yield wait(100)
done()
}))
afterEach(co.wrap(function * (done) {
afterEach(wrapCo(function * (done) {
yield compareAllUsers(this.users)
done()
}))
describe('Basic tests', function () {
it('insert three elements, try re-get property', co.wrap(function * (done) {
it('insert three elements, try re-get property', wrapCo(function * (done) {
console.log("blahhhhhhhhhhhhhhhhh ")
var array = yield y1.set('Array', Y.Array)
array.insert(0, [1, 2, 3])
array = yield y1.get('Array') // re-get property
expect(array.toArray()).toEqual([1, 2, 3])
done()
}))
it('Basic insert in array (handle three conflicts)', co.wrap(function * (done) {
it('Basic insert in array (handle three conflicts)', wrapCo(function * (done) {
yield y1.set('Array', Y.Array)
yield flushAll()
var l1 = yield y1.get('Array')
@@ -42,7 +44,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual(l3.toArray())
done()
}))
it('Basic insert&delete in array (handle three conflicts)', co.wrap(function * (done) {
it('Basic insert&delete in array (handle three conflicts)', wrapCo(function * (done) {
var l1, l2, l3
l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z'])
@@ -59,7 +61,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual([0, 2, 'y'])
done()
}))
it('Handles getOperations ascending ids bug in late sync', co.wrap(function * (done) {
it('Handles getOperations ascending ids bug in late sync', wrapCo(function * (done) {
var l1, l2
l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y'])
@@ -78,7 +80,7 @@ describe('Array Type', function () {
expect(l1.toArray()).toEqual(l2.toArray())
done()
}))
it('Handles deletions in late sync', co.wrap(function * (done) {
it('Handles deletions in late sync', wrapCo(function * (done) {
var l1, l2
l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y'])
@@ -95,7 +97,7 @@ describe('Array Type', function () {
expect(l1.toArray()).toEqual(l2.toArray())
done()
}))
it('Handles deletions in late sync (2)', co.wrap(function * (done) {
it('Handles deletions in late sync (2)', wrapCo(function * (done) {
var l1, l2
l1 = yield y1.set('Array', Y.Array)
yield flushAll()
@@ -109,7 +111,7 @@ describe('Array Type', function () {
yield compareAllUsers(this.users)
done()
}))
it('Basic insert. Then delete the whole array', co.wrap(function * (done) {
it('Basic insert. Then delete the whole array', wrapCo(function * (done) {
var l1, l2, l3
l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z'])
@@ -123,7 +125,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual([])
done()
}))
it('Basic insert. Then delete the whole array (merge listeners on late sync)', co.wrap(function * (done) {
it('Basic insert. Then delete the whole array (merge listeners on late sync)', wrapCo(function * (done) {
var l1, l2, l3
l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z'])
@@ -141,7 +143,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual([])
done()
}))
it('Basic insert. Then delete the whole array (merge deleter on late sync)', co.wrap(function * (done) {
it('Basic insert. Then delete the whole array (merge deleter on late sync)', wrapCo(function * (done) {
var l1, l2, l3
l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z'])
@@ -159,7 +161,7 @@ describe('Array Type', function () {
expect(l2.toArray()).toEqual([])
done()
}))
it('throw insert & delete events', co.wrap(function * (done) {
it('throw insert & delete events', wrapCo(function * (done) {
var array = yield this.users[0].root.set('array', Y.Array)
var event
array.observe(function (e) {
@@ -182,7 +184,7 @@ describe('Array Type', function () {
yield wait(50)
done()
}))
it('garbage collects', co.wrap(function * (done) {
it('garbage collects', wrapCo(function * (done) {
var l1, l2, l3
l1 = yield y1.set('Array', Y.Array)
l1.insert(0, ['x', 'y', 'z'])
@@ -227,7 +229,7 @@ describe('Array Type', function () {
}
}
}
beforeEach(co.wrap(function * (done) {
beforeEach(wrapCo(function * (done) {
yield this.users[0].root.set('Array', Y.Array)
yield flushAll()
@@ -238,11 +240,11 @@ describe('Array Type', function () {
this.arrays = yield Promise.all(promises)
done()
}))
it('arrays.length equals users.length', co.wrap(function * (done) { // eslint-disable-line
it('arrays.length equals users.length', wrapCo(function * (done) { // eslint-disable-line
expect(this.arrays.length).toEqual(this.users.length)
done()
}))
it(`succeed after ${numberOfYArrayTests} actions`, co.wrap(function * (done) {
it(`succeed after ${numberOfYArrayTests} actions`, wrapCo(function * (done) {
for (var u of this.users) {
u.connector.debug = true
}

View File

@@ -1,14 +1,15 @@
/* global EventHandler, Y, CustomType, copyObject, compareIds */
/* global Y */
'use strict'
;(function () {
class YMap {
constructor (os, model) {
this._model = model.id
this.os = os
this.map = copyObject(model.map)
this.map = Y.utils.copyObject(model.map)
this.contents = {}
this.opContents = {}
this.eventHandler = new EventHandler(ops => {
this.eventHandler = new Y.utils.EventHandler(ops => {
var userEvents = []
for (var i in ops) {
var op = ops[i]
@@ -61,7 +62,7 @@
userEvents.push(insertEvent)
}
} else if (op.struct === 'Delete') {
if (compareIds(this.map[key], op.target)) {
if (Y.utils.compareIds(this.map[key], op.target)) {
delete this.opContents[key]
delete this.contents[key]
var deleteEvent = {
@@ -85,7 +86,7 @@
// if property is a type, return a promise
if (this.opContents[key] == null) {
if (key == null) {
return copyObject(this.contents)
return Y.utils.copyObject(this.contents)
} else {
return this.contents[key]
}
@@ -106,7 +107,7 @@
struct: 'Delete'
}
var eventHandler = this.eventHandler
var modDel = copyObject(del)
var modDel = Y.utils.copyObject(del)
modDel.key = key
eventHandler.awaitAndPrematurelyCall([modDel])
this.os.requestTransaction(function *() {
@@ -130,7 +131,7 @@
struct: 'Insert'
}
var def = Promise.defer()
if (value instanceof CustomType) {
if (value instanceof Y.utils.CustomType) {
// construct a new type
this.os.requestTransaction(function *() {
var type = yield* value.createType.call(this)
@@ -208,7 +209,7 @@
this.eventHandler.receivedOp(op)
}
}
Y.Map = new CustomType({
Y.Map = new Y.utils.CustomType({
class: YMap,
createType: function * YMapCreator () {
var model = {

View File

@@ -1,13 +1,13 @@
/* global createUsers, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, co */
/* global createUsers, Y, compareAllUsers, getRandomNumber, applyRandomTransactions, wrapCo */
/* eslint-env browser,jasmine */
var numberOfYMapTests = 100
var numberOfYMapTests = 5
describe('Map Type', function () {
var y1, y2, y3, y4, flushAll
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000
beforeEach(co.wrap(function * (done) {
beforeEach(wrapCo(function * (done) {
yield createUsers(this, 5)
y1 = this.users[0].root
y2 = this.users[1].root
@@ -16,13 +16,13 @@ describe('Map Type', function () {
flushAll = this.users[0].connector.flushAll
done()
}))
afterEach(co.wrap(function * (done) {
afterEach(wrapCo(function * (done) {
yield compareAllUsers(this.users)
done()
}), 5000)
describe('Basic tests', function () {
it('Basic get&set of Map property (converge via sync)', co.wrap(function * (done) {
it('Basic get&set of Map property (converge via sync)', wrapCo(function * (done) {
y1.set('stuff', 'stuffy')
expect(y1.get('stuff')).toEqual('stuffy')
yield flushAll()
@@ -33,7 +33,7 @@ describe('Map Type', function () {
yield compareAllUsers(this.users)
done()
}))
it('Map can set custom types (Map)', co.wrap(function * (done) {
it('Map can set custom types (Map)', wrapCo(function * (done) {
var map = yield y1.set('Map', Y.Map)
map.set('one', 1)
map = yield y1.get('Map')
@@ -41,7 +41,7 @@ describe('Map Type', function () {
yield compareAllUsers(this.users)
done()
}))
it('Map can set custom types (Array)', co.wrap(function * (done) {
it('Map can set custom types (Array)', wrapCo(function * (done) {
var array = yield y1.set('Array', Y.Array)
array.insert(0, [1, 2, 3])
array = yield y1.get('Array')
@@ -49,7 +49,7 @@ describe('Map Type', function () {
yield compareAllUsers(this.users)
done()
}))
it('Basic get&set of Map property (converge via update)', co.wrap(function * (done) {
it('Basic get&set of Map property (converge via update)', wrapCo(function * (done) {
yield flushAll()
y1.set('stuff', 'stuffy')
expect(y1.get('stuff')).toEqual('stuffy')
@@ -61,7 +61,7 @@ describe('Map Type', function () {
}
done()
}))
it('Basic get&set of Map property (handle conflict)', co.wrap(function * (done) {
it('Basic get&set of Map property (handle conflict)', wrapCo(function * (done) {
yield flushAll()
y1.set('stuff', 'c0')
@@ -75,7 +75,7 @@ describe('Map Type', function () {
yield compareAllUsers(this.users)
done()
}))
it('Basic get&set&delete of Map property (handle conflict)', co.wrap(function * (done) {
it('Basic get&set&delete of Map property (handle conflict)', wrapCo(function * (done) {
yield flushAll()
y1.set('stuff', 'c0')
y1.delete('stuff')
@@ -89,7 +89,7 @@ describe('Map Type', function () {
yield compareAllUsers(this.users)
done()
}))
it('Basic get&set of Map property (handle three conflicts)', co.wrap(function * (done) {
it('Basic get&set of Map property (handle three conflicts)', wrapCo(function * (done) {
yield flushAll()
y1.set('stuff', 'c0')
y2.set('stuff', 'c1')
@@ -104,7 +104,7 @@ describe('Map Type', function () {
yield compareAllUsers(this.users)
done()
}))
it('Basic get&set&delete of Map property (handle three conflicts)', co.wrap(function * (done) {
it('Basic get&set&delete of Map property (handle three conflicts)', wrapCo(function * (done) {
yield flushAll()
y1.set('stuff', 'c0')
y2.set('stuff', 'c1')
@@ -125,7 +125,7 @@ describe('Map Type', function () {
yield compareAllUsers(this.users)
done()
}))
it('throws add & update & delete events (with type and primitive content)', co.wrap(function * (done) {
it('throws add & update & delete events (with type and primitive content)', wrapCo(function * (done) {
var event
yield flushAll()
y1.observe(function (e) {
@@ -186,7 +186,7 @@ describe('Map Type', function () {
}
}
}
beforeEach(co.wrap(function * (done) {
beforeEach(wrapCo(function * (done) {
yield y1.set('Map', Y.Map)
yield flushAll()
@@ -197,7 +197,7 @@ describe('Map Type', function () {
this.maps = yield Promise.all(promises)
done()
}))
it(`succeed after ${numberOfYMapTests} actions`, co.wrap(function * (done) {
it(`succeed after ${numberOfYMapTests} actions`, wrapCo(function * (done) {
yield applyRandomTransactions(this.users, this.maps, randomMapTransactions, numberOfYMapTests)
yield flushAll()
yield compareMapValues(this.maps)

View File

@@ -1,9 +1,8 @@
/* global Y */
var CustomType = Y.CustomType
'use strict'
;(function () {
class YTextBind extends Y . Array . class {
class YTextBind extends Y.Array.class {
constructor (os, _model, idArray, valArray) {
super(os, _model, idArray, valArray)
this.textfields = []
@@ -12,7 +11,7 @@ var CustomType = Y.CustomType
return this.valArray.join('')
}
insert (pos, content) {
super(pos, content.split(''))
super.insert(pos, content.split(''))
}
bind (textfield, domRoot) {
domRoot = domRoot || window; // eslint-disable-line
@@ -265,7 +264,7 @@ var CustomType = Y.CustomType
}
}
}
Y.TextBind = new CustomType({
Y.TextBind = new Y.utils.CustomType({
class: YTextBind,
createType: function * YTextBindCreator () {
var model = {