|
|
@@ -1,13 +1,14 @@
|
|
|
describe('Batcher', function () {
|
|
|
|
|
|
- var batcher = require('vue/src/batcher'),
|
|
|
+ var Batcher = require('vue/src/batcher'),
|
|
|
+ batcher = new Batcher(),
|
|
|
nextTick = require('vue/src/utils').nextTick
|
|
|
|
|
|
var updateCount = 0
|
|
|
- function mockBinding (id, middleware) {
|
|
|
+ function mockJob (id, middleware) {
|
|
|
return {
|
|
|
id: id,
|
|
|
- _update: function () {
|
|
|
+ execute: function () {
|
|
|
updateCount++
|
|
|
this.updated = true
|
|
|
if (middleware) middleware()
|
|
|
@@ -15,13 +16,13 @@ describe('Batcher', function () {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- it('should queue bindings to be updated on nextTick', function (done) {
|
|
|
+ it('should push bindings to be updated on nextTick', function (done) {
|
|
|
|
|
|
updateCount = 0
|
|
|
- var b1 = mockBinding(1),
|
|
|
- b2 = mockBinding(2)
|
|
|
- batcher.queue(b1)
|
|
|
- batcher.queue(b2)
|
|
|
+ var b1 = mockJob(1),
|
|
|
+ b2 = mockJob(2)
|
|
|
+ batcher.push(b1)
|
|
|
+ batcher.push(b2)
|
|
|
assert.strictEqual(updateCount, 0)
|
|
|
assert.notOk(b1.updated)
|
|
|
assert.notOk(b2.updated)
|
|
|
@@ -35,13 +36,13 @@ describe('Batcher', function () {
|
|
|
|
|
|
})
|
|
|
|
|
|
- it('should not queue dupicate bindings', function (done) {
|
|
|
+ it('should not push dupicate bindings', function (done) {
|
|
|
|
|
|
updateCount = 0
|
|
|
- var b1 = mockBinding(1),
|
|
|
- b2 = mockBinding(1)
|
|
|
- batcher.queue(b1)
|
|
|
- batcher.queue(b2)
|
|
|
+ var b1 = mockJob(1),
|
|
|
+ b2 = mockJob(1)
|
|
|
+ batcher.push(b1)
|
|
|
+ batcher.push(b2)
|
|
|
|
|
|
nextTick(function () {
|
|
|
assert.strictEqual(updateCount, 1)
|
|
|
@@ -52,14 +53,14 @@ describe('Batcher', function () {
|
|
|
|
|
|
})
|
|
|
|
|
|
- it('should queue dependency bidnings triggered during flush', function (done) {
|
|
|
+ it('should push dependency bidnings triggered during flush', function (done) {
|
|
|
|
|
|
updateCount = 0
|
|
|
- var b1 = mockBinding(1),
|
|
|
- b2 = mockBinding(2, function () {
|
|
|
- batcher.queue(b1)
|
|
|
+ var b1 = mockJob(1),
|
|
|
+ b2 = mockJob(2, function () {
|
|
|
+ batcher.push(b1)
|
|
|
})
|
|
|
- batcher.queue(b2)
|
|
|
+ batcher.push(b2)
|
|
|
|
|
|
nextTick(function () {
|
|
|
assert.strictEqual(updateCount, 2)
|
|
|
@@ -70,4 +71,39 @@ describe('Batcher', function () {
|
|
|
|
|
|
})
|
|
|
|
|
|
+ it('should allow overriding jobs with same ID', function (done) {
|
|
|
+
|
|
|
+ updateCount = 0
|
|
|
+ var b1 = mockJob(1),
|
|
|
+ b2 = mockJob(1)
|
|
|
+
|
|
|
+ b2.override = true
|
|
|
+ batcher.push(b1)
|
|
|
+ batcher.push(b2)
|
|
|
+
|
|
|
+ nextTick(function () {
|
|
|
+ assert.strictEqual(updateCount, 1)
|
|
|
+ assert.ok(b1.cancelled)
|
|
|
+ assert.notOk(b1.updated)
|
|
|
+ assert.ok(b2.updated)
|
|
|
+ done()
|
|
|
+ })
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
+ it('should execute the _preFlush hook', function (done) {
|
|
|
+
|
|
|
+ var executed = false
|
|
|
+ batcher._preFlush = function () {
|
|
|
+ executed = true
|
|
|
+ }
|
|
|
+ batcher.push(mockJob(1))
|
|
|
+
|
|
|
+ nextTick(function () {
|
|
|
+ assert.ok(executed)
|
|
|
+ done()
|
|
|
+ })
|
|
|
+
|
|
|
+ })
|
|
|
+
|
|
|
})
|