working push/pop

This commit is contained in:
Adam Bradley
2015-05-13 08:54:11 -05:00
parent aa4efdd12a
commit ab2b78a99c
3 changed files with 26 additions and 15 deletions

View File

@ -152,8 +152,9 @@ export class NavBase {
this.remove(item); this.remove(item);
i = 0; i = 0;
ii = this.items.length; ii = this.items.length;
debugger util.dom.raf(() => {
item.dispose && item.dispose(); item.destroy();
});
} }
} }
} }
@ -211,9 +212,8 @@ debugger
return this.items.length; return this.items.length;
} }
remove(index) { remove(itemOrIndex) {
const item = this.items[index]; util.array.remove(this.items, itemOrIndex);
this.items.splice(index, 1);
} }
getToolbars(pos: String) { getToolbars(pos: String) {

View File

@ -35,7 +35,6 @@ export class NavItem {
.then((componentRef) => { .then((componentRef) => {
this.component = componentRef; this.component = componentRef;
this.dispose = componentRef._dispose;
this.domElement = componentRef.location.domElement; this.domElement = componentRef.location.domElement;
this.domElement.classList.add('nav-item'); this.domElement.classList.add('nav-item');
@ -55,4 +54,10 @@ export class NavItem {
return promise; return promise;
} }
destroy() {
this.component && this.component._dispose && this.component._dispose();
this.domElement = this.component = this.params = this.nav = null;
}
} }

View File

@ -68,12 +68,13 @@ export function defaults(dest) {
return dest; return dest;
} }
export const isString = val => typeof val === 'string' export const isString = val => typeof val === 'string';
export const isFunction = val => typeof val === 'function' export const isNumber = val => typeof val === 'number';
export const isDefined = val => typeof val !== 'undefined' export const isFunction = val => typeof val === 'function';
export const isUndefined = val => typeof val === 'undefined' export const isDefined = val => typeof val !== 'undefined';
export const isObject = val => typeof val === 'object' export const isUndefined = val => typeof val === 'undefined';
export const isArray = Array.isArray export const isObject = val => typeof val === 'object';
export const isArray = Array.isArray;
/** /**
* Convert a string in the format thisIsAString to a slug format this-is-a-string * Convert a string in the format thisIsAString to a slug format this-is-a-string
@ -113,9 +114,14 @@ export let array = {
if (cb(arr[i], i)) return arr[i]; if (cb(arr[i], i)) return arr[i];
} }
}, },
remove(arr, item) { remove(arr, itemOrIndex) {
const index = arr.indexOf(item); let index = -1;
if (index === -1) { if (isNumber(itemOrIndex)) {
index = itemOrIndex;
} else {
index = arr.indexOf(itemOrIndex);
}
if (index < 0) {
return false; return false;
} }
arr.splice(index, 1); arr.splice(index, 1);