Skip to content

Commit

Permalink
Merge pull request #493 from entrylabs/issue/4886
Browse files Browse the repository at this point in the history
FieldStatement bug fix
  • Loading branch information
chanlee authored Oct 19, 2016
2 parents 6f8da14 + 11d6b17 commit e6cdb13
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 20 deletions.
22 changes: 16 additions & 6 deletions dist/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20901,9 +20901,9 @@ Entry.BlockView.pngMap = {};
};
b._startContentRender = function(a) {
a = void 0 === a ? Entry.Workspace.MODE_BOARD : a;
this.contentSvgGroup && this.contentSvgGroup.remove();
var b = this._schema;
b.statements && b.statements.length && this.statementSvgGroup && this.statementSvgGroup.remove();
this.contentSvgGroup && this.contentSvgGroup.remove();
this.statementSvgGroup && this.statementSvgGroup.remove();
this._contents = [];
this.contentSvgGroup = this.svgGroup.elem("g", {class:"contentsGroup"});
b.statements && b.statements.length && (this.statementSvgGroup = this.svgGroup.elem("g", {class:"statementGroup"}));
Expand Down Expand Up @@ -21094,8 +21094,7 @@ Entry.BlockView.pngMap = {};
var f = this.dragInstance && this.dragInstance.isNew, g = Entry.GlobalSvg;
a = !1;
var h = this.block.getPrevBlock(this.block);
a = !1;
switch(Entry.GlobalSvg.terminateDrag(this)) {
switch(g.terminateDrag(this)) {
case g.DONE:
g = b.magnetedBlockView;
g instanceof Entry.BlockView && (g = g.block);
Expand Down Expand Up @@ -21154,6 +21153,9 @@ Entry.BlockView.pngMap = {};
this._contents.forEach(function(a) {
a.constructor !== Entry.Block && a.destroy();
});
this._statements.forEach(function(a) {
a.destroy();
});
var c = this.block;
a = c.events.viewDestroy;
"workspace" == Entry.type && a && !this.isInBlockMenu && a.forEach(function(a) {
Expand Down Expand Up @@ -22823,6 +22825,7 @@ Entry.FieldStatement = function(b, a, d) {
this.acceptType = b.accept;
this._thread = this.statementSvgGroup = this.svgGroup = null;
this._position = b.position;
this._events = [];
this.observe(a, "alignContent", ["height"], !1);
this.observe(this, "_updateBG", ["magneting"], !1);
this.renderStart(a.getBoard());
Expand All @@ -22844,8 +22847,10 @@ Entry.FieldStatement = function(b, a, d) {
if (a = b.getFirstBlock()) {
a.view._toLocalCoordinate(this.statementSvgGroup), this.firstBlock = a;
}
b.changeEvent.attach(this, this.calcHeight);
b.changeEvent.attach(this, this.checkTopBlock);
a = b.changeEvent.attach(this, this.calcHeight);
var c = b.changeEvent.attach(this, this.checkTopBlock);
this._events.push([b.changeEvent, a]);
this._events.push([b.changeEvent, c]);
this.calcHeight();
};
b.align = function(a, b, c) {
Expand Down Expand Up @@ -22873,6 +22878,10 @@ Entry.FieldStatement = function(b, a, d) {
this._blockView.dominate();
};
b.destroy = function() {
for (;this._events.length;) {
var a = this._events.pop();
a[0].detach(a[1]);
}
};
b._updateBG = function() {
if (this._board.dragBlock && this._board.dragBlock.dragInstance) {
Expand Down Expand Up @@ -24304,6 +24313,7 @@ Entry.Block.DELETABLE_FALSE_LIGHTEN = 3;
this.view || (this.set({view:new Entry.BlockView(this, a, b)}), this._updatePos());
};
b.destroyView = function() {
this.view.destroy();
this.set({view:null});
};
b.clone = function(a) {
Expand Down
1 change: 1 addition & 0 deletions src/workspace/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Entry.Block.DELETABLE_FALSE_LIGHTEN = 3;
};

p.destroyView = function() {
this.view.destroy();
this.set({view: null});
};

Expand Down
19 changes: 13 additions & 6 deletions src/workspace/block_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,18 +178,21 @@ Entry.BlockView.pngMap = {};
p._startContentRender = function(mode) {
mode = mode === undefined ?
Entry.Workspace.MODE_BOARD : mode;

var schema = this._schema;
if (this.contentSvgGroup)
this.contentSvgGroup.remove();
var schema = this._schema;
if (schema.statements && schema.statements.length && this.statementSvgGroup)
if (this.statementSvgGroup)
this.statementSvgGroup.remove();

this._contents = [];

this.contentSvgGroup = this.svgGroup.elem("g", {class:'contentsGroup'});
if (schema.statements && schema.statements.length)
if (schema.statements && schema.statements.length) {
this.statementSvgGroup = this.svgGroup.elem("g", {
class: 'statementGroup'
});
}

switch (mode) {
case Entry.Workspace.MODE_BOARD:
Expand Down Expand Up @@ -608,11 +611,11 @@ Entry.BlockView.pngMap = {};
var gs = Entry.GlobalSvg;
var ripple = false;
var prevBlock = this.block.getPrevBlock(this.block);
var ripple = false;
switch (Entry.GlobalSvg.terminateDrag(this)) {
switch (gs.terminateDrag(this)) {
case gs.DONE:
var closeBlock = board.magnetedBlockView;
if (closeBlock instanceof Entry.BlockView) closeBlock = closeBlock.block;
if (closeBlock instanceof Entry.BlockView)
closeBlock = closeBlock.block;
if (prevBlock && !closeBlock) {
Entry.do("separateBlock", block);
} else if (!prevBlock && !closeBlock && !fromBlockMenu) {
Expand Down Expand Up @@ -736,6 +739,10 @@ Entry.BlockView.pngMap = {};
if (c.constructor !== Entry.Block) c.destroy();
});

this._statements.forEach(function(s) {
s.destroy();
});

var block = this.block;
var events = block.events.viewDestroy;
if (Entry.type == 'workspace' && events && !this.isInBlockMenu)
Expand Down
26 changes: 18 additions & 8 deletions src/workspace/field/statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Entry.FieldStatement = function(content, blockView, index) {

this._position = content.position;

this._events = [];

this.observe(blockView, "alignContent", ["height"], false);
this.observe(this, "_updateBG", ["magneting"], false);

Expand All @@ -42,13 +44,13 @@ Entry.FieldStatement = function(content, blockView, index) {
magneting: false
};

p.magnet = {
next: {x: 0, y: 0}
};
p.magnet = { next: {x: 0, y: 0} };

p.renderStart = function(board) {
this.svgGroup = this._blockView.statementSvgGroup.elem('g');
this.statementSvgGroup = this.svgGroup.elem('g');
this.svgGroup =
this._blockView.statementSvgGroup.elem('g');
this.statementSvgGroup =
this.svgGroup.elem('g');
this._nextGroup = this.statementSvgGroup;
this._initThread(board);
this._board = board;
Expand All @@ -64,8 +66,11 @@ Entry.FieldStatement = function(content, blockView, index) {
firstBlock.view._toLocalCoordinate(this.statementSvgGroup);
this.firstBlock = firstBlock;
}
thread.changeEvent.attach(this, this.calcHeight);
thread.changeEvent.attach(this, this.checkTopBlock);

var calcEvent = thread.changeEvent.attach(this, this.calcHeight);
var checkTopEvent = thread.changeEvent.attach(this, this.checkTopBlock);
this._events.push([thread.changeEvent, calcEvent]);
this._events.push([thread.changeEvent, checkTopEvent]);
this.calcHeight();
};

Expand Down Expand Up @@ -113,7 +118,12 @@ Entry.FieldStatement = function(content, blockView, index) {
this._blockView.dominate();
};

p.destroy = function() {};
p.destroy = function() {
while (this._events.length) {
var evt = this._events.pop();
evt[0].detach(evt[1])
}
};

p._updateBG = function() {
if (!this._board.dragBlock || !this._board.dragBlock.dragInstance)
Expand Down

0 comments on commit e6cdb13

Please sign in to comment.