Reorganizing and cleanup of base Node code

This commit is contained in:
Jeff Avallone 2015-04-19 12:05:59 -04:00
parent 00376bc78a
commit 8796c1329c
2 changed files with 28 additions and 61 deletions

View File

@ -217,26 +217,6 @@ describe('parser/javascript/node.js', function() {
}); });
describe('#startRender', function() {
it('increments the renderCounter', function() {
this.node.state.renderCounter = 0;
this.node.startRender();
expect(this.node.state.renderCounter).toEqual(1);
});
});
describe('#doneRender', function() {
it('decrements the renderCounter', function() {
this.node.state.renderCounter = 42;
this.node.doneRender();
expect(this.node.state.renderCounter).toEqual(41);
});
});
describe('#render', function() { describe('#render', function() {
beforeEach(function() { beforeEach(function() {
@ -267,8 +247,6 @@ describe('parser/javascript/node.js', function() {
beforeEach(function() { beforeEach(function() {
this.deferred = this.testablePromise(); this.deferred = this.testablePromise();
this.node._render = jasmine.createSpy('_render').and.returnValue(this.deferred.promise); this.node._render = jasmine.createSpy('_render').and.returnValue(this.deferred.promise);
spyOn(this.node, 'startRender');
spyOn(this.node, 'doneRender');
}); });
it('sets the container', function() { it('sets the container', function() {
@ -276,9 +254,10 @@ describe('parser/javascript/node.js', function() {
expect(this.node.container).toEqual(this.container); expect(this.node.container).toEqual(this.container);
}); });
it('calls #startRender', function() { it('increments the renderCounter', function() {
this.node.state.renderCounter = 0;
this.node.render(this.container); this.node.render(this.container);
expect(this.node.startRender).toHaveBeenCalled(); expect(this.node.state.renderCounter).toEqual(1);
}); });
it('calls #_render', function() { it('calls #_render', function() {
@ -288,19 +267,18 @@ describe('parser/javascript/node.js', function() {
describe('when #_render is complete', function() { describe('when #_render is complete', function() {
beforeEach(function() { it('decrements the renderCounter', function(done) {
this.node.render(this.container)
.then(() => {
expect(this.node.state.renderCounter).toEqual(41);
done();
});
this.node.state.renderCounter = 42;
this.deferred.resolve(); this.deferred.resolve();
}); });
it('calls #doneRender', function(done) {
this.node.render(this.container)
.then(() => {
expect(this.node.doneRender).toHaveBeenCalled();
done();
});
});
it('ultimately resolves with the node instance', function(done) { it('ultimately resolves with the node instance', function(done) {
this.deferred.resolve();
this.node.render(this.container) this.node.render(this.container)
.then(result => { .then(result => {
expect(result).toEqual(this.node); expect(result).toEqual(this.node);

View File

@ -59,6 +59,23 @@ export default class Node {
}); });
} }
render(container) {
if (container) {
this.container = container;
}
if (this.proxy) {
return this.proxy.render(this.container);
} else {
this.state.renderCounter++;
return this._render()
.then(() => {
this.state.renderCounter--;
return this;
});
}
}
renderLabel(text) { renderLabel(text) {
var group = this.container.group() var group = this.container.group()
.addClass('label'), .addClass('label'),
@ -82,34 +99,6 @@ export default class Node {
}); });
} }
startRender() {
this.state.renderCounter++;
}
doneRender() {
this.state.renderCounter--;
}
render(container) {
if (container) {
this.container = container;
}
if (this.proxy) {
return this.proxy.render(this.container);
} else {
this.startRender();
return this._render()
.then(
() => {
this.doneRender();
return this;
},
null
);
}
}
renderLabeledBox(label, content, options) { renderLabeledBox(label, content, options) {
var label = this.container.text(0, 0, label) var label = this.container.text(0, 0, label)
.addClass([this.type, 'label'].join('-')), .addClass([this.type, 'label'].join('-')),