#4 do not leak tick listeners!
This commit is contained in:
@@ -152,6 +152,7 @@ export default class App {
|
|||||||
if (progress >= 1) {
|
if (progress >= 1) {
|
||||||
PIXI.ticker.shared.remove(tick)
|
PIXI.ticker.shared.remove(tick)
|
||||||
that.stage.removeChild(pod)
|
that.stage.removeChild(pod)
|
||||||
|
pod.destroy()
|
||||||
originalPod.visible = true
|
originalPod.visible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -167,7 +168,7 @@ export default class App {
|
|||||||
pod.position = globalPosition.clone()
|
pod.position = globalPosition.clone()
|
||||||
pod.alpha = 1
|
pod.alpha = 1
|
||||||
pod._progress = 1
|
pod._progress = 1
|
||||||
originalPod.visible = false
|
originalPod.destroy()
|
||||||
const that = this
|
const that = this
|
||||||
const tick = function(t) {
|
const tick = function(t) {
|
||||||
// progress goes from 1 to 0
|
// progress goes from 1 to 0
|
||||||
@@ -181,6 +182,7 @@ export default class App {
|
|||||||
if (progress <= 0) {
|
if (progress <= 0) {
|
||||||
PIXI.ticker.shared.remove(tick)
|
PIXI.ticker.shared.remove(tick)
|
||||||
that.stage.removeChild(pod)
|
that.stage.removeChild(pod)
|
||||||
|
pod.destroy()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PIXI.ticker.shared.add(tick)
|
PIXI.ticker.shared.add(tick)
|
||||||
@@ -214,6 +216,8 @@ export default class App {
|
|||||||
window.setTimeout(function() {
|
window.setTimeout(function() {
|
||||||
that.animatePodDeletion(pod, globalPos)
|
that.animatePodDeletion(pod, globalPos)
|
||||||
}, 100 * changes)
|
}, 100 * changes)
|
||||||
|
} else {
|
||||||
|
pod.destroy()
|
||||||
}
|
}
|
||||||
changes++
|
changes++
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ export class Pod extends PIXI.Graphics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
destroy() {
|
||||||
|
if (this.tick) {
|
||||||
|
PIXI.ticker.shared.remove(this.tick, this)
|
||||||
|
}
|
||||||
|
super.destroy()
|
||||||
|
}
|
||||||
|
|
||||||
animateMove(time) {
|
animateMove(time) {
|
||||||
const deltaX = this._targetPosition.x - this.position.x
|
const deltaX = this._targetPosition.x - this.position.x
|
||||||
const deltaY = this._targetPosition.y - this.position.y
|
const deltaY = this._targetPosition.y - this.position.y
|
||||||
@@ -108,7 +115,6 @@ export class Pod extends PIXI.Graphics {
|
|||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
|
|
||||||
|
|
||||||
// pod.status.containerStatuses might be undefined!
|
// pod.status.containerStatuses might be undefined!
|
||||||
const containerStatuses = this.pod.status.containerStatuses || []
|
const containerStatuses = this.pod.status.containerStatuses || []
|
||||||
var ready = 0
|
var ready = 0
|
||||||
@@ -225,10 +231,12 @@ export class Pod extends PIXI.Graphics {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newTick) {
|
if (newTick && newTick != this.tick) {
|
||||||
this.tick = newTick
|
this.tick = newTick
|
||||||
|
// important: only register new listener if it does not exist yet!
|
||||||
|
// (otherwise we leak listeners)
|
||||||
PIXI.ticker.shared.add(this.tick, this)
|
PIXI.ticker.shared.add(this.tick, this)
|
||||||
} else if (this.tick) {
|
} else if (!newTick && this.tick) {
|
||||||
PIXI.ticker.shared.remove(this.tick, this)
|
PIXI.ticker.shared.remove(this.tick, this)
|
||||||
this.tick = null
|
this.tick = null
|
||||||
this.alpha = this._progress
|
this.alpha = this._progress
|
||||||
|
|||||||
Reference in New Issue
Block a user