From dd0545105ffbbbbd37aff1d739970eb4ea95bbd5 Mon Sep 17 00:00:00 2001 From: vivid Date: Tue, 18 Oct 2016 14:23:34 +0900 Subject: [PATCH] FieldStatement bug fix FieldStatement event listening bug fix --- dist/entry.js | 22 ++++++++++++++++------ src/workspace/block.js | 1 + src/workspace/block_view.js | 19 +++++++++++++------ src/workspace/field/statement.js | 26 ++++++++++++++++++-------- 4 files changed, 48 insertions(+), 20 deletions(-) diff --git a/dist/entry.js b/dist/entry.js index b4011bb4e7..58842b875e 100644 --- a/dist/entry.js +++ b/dist/entry.js @@ -20892,9 +20892,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"})); @@ -21085,8 +21085,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); @@ -21145,6 +21144,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) { @@ -22810,6 +22812,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()); @@ -22831,8 +22834,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) { @@ -22860,6 +22865,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) { @@ -24284,6 +24293,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) { diff --git a/src/workspace/block.js b/src/workspace/block.js index 3fd07ebe98..c2bed63439 100644 --- a/src/workspace/block.js +++ b/src/workspace/block.js @@ -177,6 +177,7 @@ Entry.Block.DELETABLE_FALSE_LIGHTEN = 3; }; p.destroyView = function() { + this.view.destroy(); this.set({view: null}); }; diff --git a/src/workspace/block_view.js b/src/workspace/block_view.js index 86c926f98b..acb41d6c4d 100644 --- a/src/workspace/block_view.js +++ b/src/workspace/block_view.js @@ -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: @@ -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) { @@ -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) diff --git a/src/workspace/field/statement.js b/src/workspace/field/statement.js index 4b0189d929..9ab2c1320a 100644 --- a/src/workspace/field/statement.js +++ b/src/workspace/field/statement.js @@ -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); @@ -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; @@ -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(); }; @@ -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)