mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 13:32:54 +08:00
chore(util): add removeArrayItem fn
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import { Menu } from './menu';
|
import { Menu } from './menu';
|
||||||
import { MenuType } from './menu-types';
|
import { MenuType } from './menu-types';
|
||||||
import { Platform } from '../../platform/platform';
|
import { Platform } from '../../platform/platform';
|
||||||
|
import { removeArrayItem } from '../../util/util';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -291,10 +292,7 @@ export class MenuController {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
unregister(menu: Menu) {
|
unregister(menu: Menu) {
|
||||||
let index = this._menus.indexOf(menu);
|
removeArrayItem(this._menus, menu);
|
||||||
if (index > -1) {
|
|
||||||
this._menus.splice(index, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -8,7 +8,7 @@ import { convertToView, convertToViews, NavOptions, DIRECTION_BACK, DIRECTION_FO
|
|||||||
import { setZIndex } from './nav-util';
|
import { setZIndex } from './nav-util';
|
||||||
import { DeepLinker } from './deep-linker';
|
import { DeepLinker } from './deep-linker';
|
||||||
import { GestureController } from '../gestures/gesture-controller';
|
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 { isViewController, ViewController } from './view-controller';
|
||||||
import { Ion } from '../components/ion';
|
import { Ion } from '../components/ion';
|
||||||
import { Keyboard } from '../util/keyboard';
|
import { Keyboard } from '../util/keyboard';
|
||||||
@ -893,10 +893,7 @@ export class NavControllerBase extends Ion implements NavController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unregisterChildNav(nav: any) {
|
unregisterChildNav(nav: any) {
|
||||||
const index = this._children.indexOf(nav);
|
removeArrayItem(this._children, nav);
|
||||||
if (index > -1) {
|
|
||||||
this._children.splice(index, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
|
@ -2,6 +2,7 @@ import { EventEmitter, NgZone, OpaqueToken } from '@angular/core';
|
|||||||
|
|
||||||
import { QueryParams } from './query-params';
|
import { QueryParams } from './query-params';
|
||||||
import { ready, windowDimensions, flushDimensionCache } from '../util/dom';
|
import { ready, windowDimensions, flushDimensionCache } from '../util/dom';
|
||||||
|
import { removeArrayItem } from '../util/util';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -373,10 +374,7 @@ export class Platform {
|
|||||||
|
|
||||||
// return a function to unregister this back button action
|
// return a function to unregister this back button action
|
||||||
return () => {
|
return () => {
|
||||||
let index = this._bbActions.indexOf(action);
|
removeArrayItem(this._bbActions, action);
|
||||||
if (index > -1) {
|
|
||||||
this._bbActions.splice(index, 1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -524,14 +522,11 @@ export class Platform {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
onResize(cb: Function): Function {
|
onResize(cb: Function): Function {
|
||||||
let self = this;
|
const self = this;
|
||||||
self._onResizes.push(cb);
|
self._onResizes.push(cb);
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
const index = self._onResizes.indexOf(cb);
|
removeArrayItem(self._onResizes, cb);
|
||||||
if (index > -1) {
|
|
||||||
self._onResizes.splice(index, 1);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { removeArrayItem } from './util';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -15,10 +16,7 @@ export class Form {
|
|||||||
}
|
}
|
||||||
|
|
||||||
deregister(input: any) {
|
deregister(input: any) {
|
||||||
let index = this._inputs.indexOf(input);
|
removeArrayItem(this._inputs, input);
|
||||||
if (index > -1) {
|
|
||||||
this._inputs.splice(index, 1);
|
|
||||||
}
|
|
||||||
if (input === this._focused) {
|
if (input === this._focused) {
|
||||||
this._focused = null;
|
this._focused = null;
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import * as util from '../util';
|
import * as util from '../util';
|
||||||
|
|
||||||
|
describe('util', () => {
|
||||||
|
|
||||||
describe('isPrimitive', () => {
|
describe('isPrimitive', () => {
|
||||||
|
|
||||||
it('should be false for array/object values', () => {
|
it('should be false for array/object values', () => {
|
||||||
@ -360,3 +362,5 @@ describe('defaults', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
@ -148,12 +148,21 @@ export const isCheckedProperty = function(a: any, b: any): boolean {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export function reorderArray(array: any[], indexes: {from: number, to: number}): any[] {
|
export function reorderArray(array: any[], indexes: {from: number, to: number}): any[] {
|
||||||
let element = array[indexes.from];
|
const element = array[indexes.from];
|
||||||
array.splice(indexes.from, 1);
|
array.splice(indexes.from, 1);
|
||||||
array.splice(indexes.to, 0, element);
|
array.splice(indexes.to, 0, element);
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
export function removeArrayItem(array: any[], item: any) {
|
||||||
|
const index = array.indexOf(item);
|
||||||
|
return !!~index && !!array.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user