forked from mystiq/hydrogen-web
dispose tiles
also add more defence against emitting event when disposed
This commit is contained in:
parent
9ea961ae53
commit
b2e6e8687e
2 changed files with 18 additions and 4 deletions
|
@ -145,7 +145,7 @@ export class TilesCollection extends BaseObservableList {
|
||||||
if (tile) {
|
if (tile) {
|
||||||
const action = tile.updateEntry(entry, params);
|
const action = tile.updateEntry(entry, params);
|
||||||
if (action.shouldReplace) {
|
if (action.shouldReplace) {
|
||||||
this._replaceTile(tileIdx, this._tileCreator(entry));
|
this._replaceTile(tileIdx, tile, this._tileCreator(entry));
|
||||||
}
|
}
|
||||||
if (action.shouldRemove) {
|
if (action.shouldRemove) {
|
||||||
this._removeTile(tileIdx, tile);
|
this._removeTile(tileIdx, tile);
|
||||||
|
@ -167,7 +167,8 @@ export class TilesCollection extends BaseObservableList {
|
||||||
// merge with neighbours? ... hard to imagine use case for this ...
|
// merge with neighbours? ... hard to imagine use case for this ...
|
||||||
}
|
}
|
||||||
|
|
||||||
_replaceTile(tileIdx, newTile) {
|
_replaceTile(tileIdx, existingTile, newTile) {
|
||||||
|
existingTile.dispose();
|
||||||
const prevTile = this._getTileAtIdx(tileIdx - 1);
|
const prevTile = this._getTileAtIdx(tileIdx - 1);
|
||||||
const nextTile = this._getTileAtIdx(tileIdx + 1);
|
const nextTile = this._getTileAtIdx(tileIdx + 1);
|
||||||
this._tiles[tileIdx] = newTile;
|
this._tiles[tileIdx] = newTile;
|
||||||
|
@ -184,7 +185,7 @@ export class TilesCollection extends BaseObservableList {
|
||||||
this._tiles.splice(tileIdx, 1);
|
this._tiles.splice(tileIdx, 1);
|
||||||
prevTile && prevTile.updateNextSibling(nextTile);
|
prevTile && prevTile.updateNextSibling(nextTile);
|
||||||
nextTile && nextTile.updatePreviousSibling(prevTile);
|
nextTile && nextTile.updatePreviousSibling(prevTile);
|
||||||
tile.setUpdateEmit(null);
|
tile.dispose();
|
||||||
this.emitRemove(tileIdx, tile);
|
this.emitRemove(tileIdx, tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,6 +255,8 @@ export function tests() {
|
||||||
updateEntry() {
|
updateEntry() {
|
||||||
return UpdateAction.Nothing;
|
return UpdateAction.Nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispose() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -48,7 +48,13 @@ export class SimpleTile extends ViewModel {
|
||||||
}
|
}
|
||||||
// TilesCollection contract below
|
// TilesCollection contract below
|
||||||
setUpdateEmit(emitUpdate) {
|
setUpdateEmit(emitUpdate) {
|
||||||
this.updateOptions({emitChange: paramName => emitUpdate(this, paramName)});
|
this.updateOptions({emitChange: paramName => {
|
||||||
|
if (emitUpdate) {
|
||||||
|
emitUpdate(this, paramName);
|
||||||
|
} else {
|
||||||
|
console.trace("Tile is emitting event after being disposed");
|
||||||
|
}
|
||||||
|
}});
|
||||||
}
|
}
|
||||||
|
|
||||||
get upperEntry() {
|
get upperEntry() {
|
||||||
|
@ -88,5 +94,10 @@ export class SimpleTile extends ViewModel {
|
||||||
updateNextSibling(next) {
|
updateNextSibling(next) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
this.setUpdateEmit(null);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
// TilesCollection contract above
|
// TilesCollection contract above
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue