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,5 +1,7 @@
'use strict'
Y.IndexedDB = (function () { // eslint-disable-line
class Transaction extends AbstractTransaction { // eslint-disable-line
class Transaction extends Y.AbstractTransaction { // eslint-disable-line
constructor (store) {
super(store)
this.transaction = store.db.transaction(['OperationStore', 'StateVector'], 'readwrite')
@@ -79,7 +81,7 @@ Y.IndexedDB = (function () { // eslint-disable-line
return ops
}
}
class OperationStore extends AbstractOperationStore { // eslint-disable-line no-undef
class OperationStore extends Y.AbstractOperationStore { // eslint-disable-line no-undef
constructor (y, opts) {
super(y, opts)
if (opts == null) {
@@ -162,7 +164,6 @@ Y.IndexedDB = (function () { // eslint-disable-line
}
}
handleTransactions(tGen.next())
}
requestTransaction (makeGen) {
this.transactionQueue.queue.push(makeGen)

View File

@@ -1,7 +1,7 @@
/* global Y */
/* eslint-env browser,jasmine */
if (typeof window !== 'undefined') {
if (typeof window !== 'undefined' && false) {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000
describe('IndexedDB', function () {
var ob

View File

@@ -1,4 +1,4 @@
/* global Struct, RBTree, Y, compareIds */
/* global Y */
'use strict'
function copyObject (o) {
@@ -8,8 +8,9 @@ function copyObject (o) {
}
return c
}
Y.utils.copyObject = copyObject
class DeleteStore extends Y.RBTree {
class DeleteStore extends Y.utils.RBTree {
constructor () {
super()
}
@@ -36,7 +37,7 @@ class DeleteStore extends Y.RBTree {
}
// can extend right?
var next = n.next()
if (next !== null && compareIds([n.val.id[0], n.val.id[1] + n.val.len], next.val.id)) {
if (next !== null && Y.utils.compareIds([n.val.id[0], n.val.id[1] + n.val.len], next.val.id)) {
n.val.len = n.val.len + next.val.len
super.delete(next.val.id)
}
@@ -117,7 +118,7 @@ class DeleteStore extends Y.RBTree {
}
}
Y.DeleteStore = DeleteStore
Y.utils.DeleteStore = DeleteStore
Y.Memory = (function () { // eslint-disable-line no-unused-vars
class Transaction extends Y.AbstractTransaction { // eslint-disable-line
@@ -206,7 +207,7 @@ Y.Memory = (function () { // eslint-disable-line no-unused-vars
this.os.iterate([user, startPos], [user, endPos], function (op) {// eslint-disable-line
if (!op.gc) {
ops.push(Struct[op.struct].encode(op))
ops.push(Y.Struct[op.struct].encode(op))
}
})
}
@@ -251,7 +252,7 @@ Y.Memory = (function () { // eslint-disable-line no-unused-vars
class OperationStore extends Y.AbstractOperationStore { // eslint-disable-line no-undef
constructor (y, opts) {
super(y, opts)
this.os = new RBTree()
this.os = new Y.utils.RBTree()
this.ss = {}
this.waitingTransactions = []
this.transactionInProgress = false

View File

@@ -1,13 +1,11 @@
/* global Y */
/* eslint-env browser,jasmine,console */
var DeleteStore = Y.DeleteStore
describe('Memory', function () {
describe('DeleteStore', function () {
var ds
beforeEach(function () {
ds = new DeleteStore()
ds = new Y.utils.DeleteStore()
})
it('Deleted operation is deleted', function () {
ds.delete(['u1', 10])

View File

@@ -1,11 +1,10 @@
/* global Y, copyObject */
/* global Y */
'use strict'
var compareIds = Y.compareIds
function smaller (a, b) {
return a[0] < b[0] || (a[0] === b[0] && a[1] < b[1])
}
Y.utils.smaller = smaller
class N {
// A created node is always red!
@@ -190,7 +189,7 @@ class RBTree { // eslint-disable-line no-unused-vars
}
iterate (from, to, f) {
var o = this.findNodeWithLowerBound(from)
while (o !== null && (to === null || smaller(o.val.id, to) || compareIds(o.val.id, to))) {
while (o !== null && (to === null || smaller(o.val.id, to) || Y.utils.compareIds(o.val.id, to))) {
f(o.val)
o = o.next()
}
@@ -201,7 +200,7 @@ class RBTree { // eslint-disable-line no-unused-vars
if (to == null) { to = null }
var os = []
this.iterate(from, to, function (o) {
var o_ = copyObject(o)
var o_ = Y.utils.copyObject(o)
var id = o_.id
delete o_.id
o_['id[0]'] = id[0]
@@ -460,4 +459,4 @@ class RBTree { // eslint-disable-line no-unused-vars
}
}
Y.RBTree = RBTree
Y.utils.RBTree = RBTree

View File

@@ -1,9 +1,6 @@
/* global Y */
/* eslint-env browser,jasmine,console */
var RBTree = Y.RBTree
var compareIds = Y.compareIds
var smaller = Y.smaller
var numberOfRBTreeTests = 1000
function itRedNodesDoNotHaveBlackChildren (tree) {
@@ -54,7 +51,7 @@ function itRootNodeIsBlack (tree) {
describe('RedBlack Tree', function () {
beforeEach(function () {
this.tree = new RBTree()
this.tree = new Y.utils.RBTree()
})
it('can add&retrieve 5 elements', function () {
this.tree.add({val: 'four', id: [4]})
@@ -97,7 +94,7 @@ describe('RedBlack Tree', function () {
expect(this.tree.find([2])).toBeUndefined()
})
describe('debug #2', function () {
var tree = new RBTree()
var tree = new Y.utils.RBTree()
tree.add({id: [8433]})
tree.add({id: [12844]})
tree.add({id: [1795]})
@@ -114,17 +111,19 @@ describe('RedBlack Tree', function () {
describe(`After adding&deleting (0.8/0.2) ${numberOfRBTreeTests} times`, function () {
var elements = []
var tree = new RBTree()
var tree = new Y.utils.RBTree()
for (var i = 0; i < numberOfRBTreeTests; i++) {
var r = Math.random()
if (r < 0.8) {
var obj = [Math.floor(Math.random() * numberOfRBTreeTests * 10000)]
elements.push(obj)
tree.add({id: obj})
if (!tree.findNode(obj)) {
elements.push(obj)
tree.add({id: obj})
}
} else if (elements.length > 0) {
var elemid = Math.floor(Math.random() * elements.length)
var elem = elements[elemid]
elements = elements.filter(function (e) {return !compareIds(e, elem); }); // eslint-disable-line
elements = elements.filter(function (e) {return !Y.utils.compareIds(e, elem); }); // eslint-disable-line
tree.delete(elem)
}
}
@@ -148,7 +147,7 @@ describe('RedBlack Tree', function () {
it('iterating over a tree with lower bound yields the right amount of results', function () {
var lowerBound = elements[Math.floor(Math.random() * elements.length)]
var expectedResults = elements.filter(function (e, pos) {
return (smaller(lowerBound, e) || compareIds(e, lowerBound)) && elements.indexOf(e) === pos
return (Y.utils.smaller(lowerBound, e) || Y.utils.compareIds(e, lowerBound)) && elements.indexOf(e) === pos
}).length
var actualResults = 0
@@ -175,7 +174,7 @@ describe('RedBlack Tree', function () {
it('iterating over a tree with upper bound yields the right amount of results', function () {
var upperBound = elements[Math.floor(Math.random() * elements.length)]
var expectedResults = elements.filter(function (e, pos) {
return (smaller(e, upperBound) || compareIds(e, upperBound)) && elements.indexOf(e) === pos
return (Y.utils.smaller(e, upperBound) || Y.utils.compareIds(e, upperBound)) && elements.indexOf(e) === pos
}).length
var actualResults = 0
@@ -190,7 +189,7 @@ describe('RedBlack Tree', function () {
var b1 = elements[Math.floor(Math.random() * elements.length)]
var b2 = elements[Math.floor(Math.random() * elements.length)]
var upperBound, lowerBound
if (smaller(b1, b2)) {
if (Y.utils.smaller(b1, b2)) {
lowerBound = b1
upperBound = b2
} else {
@@ -198,8 +197,8 @@ describe('RedBlack Tree', function () {
upperBound = b1
}
var expectedResults = elements.filter(function (e, pos) {
return (smaller(lowerBound, e) || compareIds(e, lowerBound)) &&
(smaller(e, upperBound) || compareIds(e, upperBound)) && elements.indexOf(e) === pos
return (Y.utils.smaller(lowerBound, e) || Y.utils.compareIds(e, lowerBound)) &&
(Y.utils.smaller(e, upperBound) || Y.utils.compareIds(e, upperBound)) && elements.indexOf(e) === pos
}).length
var actualResults = 0
tree.iterate(lowerBound, upperBound, function (val) {