Skip to content

Commit

Permalink
chore(util): add removeArrayItem fn
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Nov 29, 2016
1 parent a4ab7ca commit bdf02d4
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 335 deletions.
6 changes: 2 additions & 4 deletions src/components/menu/menu-controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Menu } from './menu';
import { MenuType } from './menu-types';
import { Platform } from '../../platform/platform';
import { removeArrayItem } from '../../util/util';


/**
Expand Down Expand Up @@ -291,10 +292,7 @@ export class MenuController {
* @private
*/
unregister(menu: Menu) {
let index = this._menus.indexOf(menu);
if (index > -1) {
this._menus.splice(index, 1);
}
removeArrayItem(this._menus, menu);
}

/**
Expand Down
7 changes: 2 additions & 5 deletions src/navigation/nav-controller-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { convertToView, convertToViews, NavOptions, DIRECTION_BACK, DIRECTION_FO
import { setZIndex } from './nav-util';
import { DeepLinker } from './deep-linker';
import { GestureController } from '../gestures/gesture-controller';
import { isBlank, isNumber, isPresent, assert } from '../util/util';
import { isBlank, isNumber, isPresent, assert, removeArrayItem } from '../util/util';
import { isViewController, ViewController } from './view-controller';
import { Ion } from '../components/ion';
import { Keyboard } from '../util/keyboard';
Expand Down Expand Up @@ -893,10 +893,7 @@ export class NavControllerBase extends Ion implements NavController {
}

unregisterChildNav(nav: any) {
const index = this._children.indexOf(nav);
if (index > -1) {
this._children.splice(index, 1);
}
removeArrayItem(this._children, nav);
}

destroy() {
Expand Down
13 changes: 4 additions & 9 deletions src/platform/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EventEmitter, NgZone, OpaqueToken } from '@angular/core';

import { QueryParams } from './query-params';
import { ready, windowDimensions, flushDimensionCache } from '../util/dom';
import { removeArrayItem } from '../util/util';


/**
Expand Down Expand Up @@ -373,10 +374,7 @@ export class Platform {

// return a function to unregister this back button action
return () => {
let index = this._bbActions.indexOf(action);
if (index > -1) {
this._bbActions.splice(index, 1);
}
removeArrayItem(this._bbActions, action);
};
}

Expand Down Expand Up @@ -524,14 +522,11 @@ export class Platform {
* @private
*/
onResize(cb: Function): Function {
let self = this;
const self = this;
self._onResizes.push(cb);

return function() {
const index = self._onResizes.indexOf(cb);
if (index > -1) {
self._onResizes.splice(index, 1);
}
removeArrayItem(self._onResizes, cb);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/util/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export function rafFrames(framesToWait: number, callback: Function) {
if (framesToWait === 0) {
callback();

}else if (framesToWait < 2) {
} else if (framesToWait < 2) {
rafId = nativeRaf(callback);

} else {
Expand Down
6 changes: 2 additions & 4 deletions src/util/form.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable } from '@angular/core';
import { removeArrayItem } from './util';


/**
Expand All @@ -15,10 +16,7 @@ export class Form {
}

deregister(input: any) {
let index = this._inputs.indexOf(input);
if (index > -1) {
this._inputs.splice(index, 1);
}
removeArrayItem(this._inputs, input);
if (input === this._focused) {
this._focused = null;
}
Expand Down
Loading

0 comments on commit bdf02d4

Please sign in to comment.