mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 05:21:52 +08:00
chore(util): add removeArrayItem fn
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { Menu } from './menu';
|
||||
import { MenuType } from './menu-types';
|
||||
import { Platform } from '../../platform/platform';
|
||||
import { removeArrayItem } from '../../util/util';
|
||||
|
||||
|
||||
/**
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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';
|
||||
@ -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() {
|
||||
|
@ -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';
|
||||
|
||||
|
||||
/**
|
||||
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { removeArrayItem } from './util';
|
||||
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import * as util from '../util';
|
||||
|
||||
describe('isPrimitive', () => {
|
||||
describe('util', () => {
|
||||
|
||||
describe('isPrimitive', () => {
|
||||
|
||||
it('should be false for array/object values', () => {
|
||||
expect(util.isPrimitive({})).toEqual(false);
|
||||
@ -31,9 +33,9 @@ describe('isPrimitive', () => {
|
||||
expect(util.isPrimitive('hi')).toEqual(true);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('isCheckedProperty', () => {
|
||||
describe('isCheckedProperty', () => {
|
||||
|
||||
it('should test a=undefined', () => {
|
||||
expect(util.isCheckedProperty(undefined, undefined)).toBe(true);
|
||||
@ -260,9 +262,9 @@ describe('isCheckedProperty', () => {
|
||||
expect(util.isCheckedProperty('string', 'false')).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('isTrueProperty', () => {
|
||||
describe('isTrueProperty', () => {
|
||||
|
||||
it('should be true from boolean true', () => {
|
||||
expect(util.isTrueProperty(true)).toBe(true);
|
||||
@ -310,9 +312,9 @@ describe('isTrueProperty', () => {
|
||||
expect(util.isTrueProperty('doesnt actually matter')).toBe(false);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('extend', () => {
|
||||
describe('extend', () => {
|
||||
|
||||
it('should extend simple', () => {
|
||||
var obj = { a: '0', c: '0' };
|
||||
@ -333,9 +335,9 @@ describe('extend', () => {
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('defaults', () => {
|
||||
describe('defaults', () => {
|
||||
|
||||
it('should simple defaults', () => {
|
||||
var obj = { a: '1' };
|
||||
@ -359,4 +361,6 @@ describe('defaults', () => {
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -148,12 +148,21 @@ export const isCheckedProperty = function(a: any, b: any): boolean {
|
||||
* @private
|
||||
*/
|
||||
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.to, 0, element);
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export function removeArrayItem(array: any[], item: any) {
|
||||
const index = array.indexOf(item);
|
||||
return !!~index && !!array.splice(index, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
|
Reference in New Issue
Block a user