Skip to content

Commit 7cc87a0

Browse files
committed
refactor(common): drop IE8 shims
1 parent f639502 commit 7cc87a0

File tree

10 files changed

+29
-85
lines changed

10 files changed

+29
-85
lines changed

src/common/common.ts

+3-44
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function inherit(parent, extra) {
2525
*/
2626
export function defaults(opts = {}, ...defaultsList) {
2727
var defaults = merge.apply(null, [{}].concat(defaultsList));
28-
return extend({}, defaults, pick(opts || {}, objectKeys(defaults)));
28+
return extend({}, defaults, pick(opts || {}, Object.keys(defaults)));
2929
}
3030

3131
/**
@@ -58,47 +58,6 @@ export function ancestors(first, second) {
5858
return path;
5959
}
6060

61-
/**
62-
* IE8-safe wrapper for `Object.keys()`.
63-
*
64-
* @param {Object} object A JavaScript object.
65-
* @return {Array} Returns the keys of the object as an array.
66-
*/
67-
export function objectKeys(object): string[] {
68-
if (Object.keys) {
69-
return Object.keys(object);
70-
}
71-
var result = [];
72-
73-
forEach(object, function(val, key) {
74-
result.push(key);
75-
});
76-
return result;
77-
}
78-
79-
/**
80-
* IE8-safe wrapper for `Array.prototype.indexOf()`.
81-
*
82-
* @param {Array} array A JavaScript array.
83-
* @param {*} value A value to search the array for.
84-
* @return {Number} Returns the array index value of `value`, or `-1` if not present.
85-
*/
86-
export var arraySearch = indexOf;
87-
export function indexOf(array, value) {
88-
if (Array.prototype.indexOf) {
89-
return array.indexOf(value, Number(arguments[2]) || 0);
90-
}
91-
var len = array.length >>> 0, from = Number(arguments[2]) || 0;
92-
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
93-
94-
if (from < 0) from += len;
95-
96-
for (; from < len; from++) {
97-
if (from in array && array[from] === value) return from;
98-
}
99-
return -1;
100-
}
101-
10261
export const removeFrom = (array: any[]) => (obj) => {
10362
var idx = array.indexOf(obj);
10463
if (idx >= 0) array.splice(idx, 1);
@@ -119,11 +78,11 @@ export function inheritParams(currentParams, newParams, $current, $to) {
11978

12079
for (var i in parents) {
12180
if (!parents[i].params) continue;
122-
parentParams = objectKeys(parents[i].params);
81+
parentParams = Object.keys(parents[i].params);
12382
if (!parentParams.length) continue;
12483

12584
for (var j in parentParams) {
126-
if (indexOf(inheritList, parentParams[j]) >= 0) continue;
85+
if (inheritList.indexOf(parentParams[j]) >= 0) continue;
12786
inheritList.push(parentParams[j]);
12887
inherited[parentParams[j]] = currentParams[parentParams[j]];
12988
}

src/common/trace.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {isNull, isPromise, is, invoke, not, val, pattern, parse, objectKeys,
2-
isDefined, isFunction, identity} from "../common/common";
1+
import {isNull, isPromise, is, invoke, not, val, pattern, parse, isDefined,
2+
isFunction, identity} from "../common/common";
33
import Resolvable from "../resolve/resolvable";
44
import {Transition} from "../transition/transition";
55
import {TransitionRejection} from "../transition/rejectFactory";
@@ -87,7 +87,7 @@ class Trace {
8787
traceResolvePathElement(pathElement, resolvablePromises, options) {
8888
let tid = parse("transition.$id")(options),
8989
digest = this.approximateDigests,
90-
resolvablePromisesStr = objectKeys(resolvablePromises).join(", "),
90+
resolvablePromisesStr = Object.keys(resolvablePromises).join(", "),
9191
pathElementStr = pathElement && pathElement.toString(),
9292
policyStr = options && options.resolvePolicy;
9393
this._trace(`Transition #${tid} Digest #${digest}: Resolve ${pathElementStr} resolvables: [${resolvablePromisesStr}] (${policyStr})`);

src/params/param.ts

+4-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {isInjectable, extend, isDefined, isString, isArray, filter, map, prop, indexOf} from "../common/common";
1+
import {isInjectable, extend, isDefined, isString, isArray, filter, map, prop} from "../common/common";
22
import {runtime} from "../common/angular1";
33
import matcherConfig from "../url/urlMatcherConfig";
44
import paramTypes from "./paramTypes";
@@ -68,25 +68,12 @@ export default class Param {
6868
{from: null, to: (isOptional || arrayMode ? undefined : "")}
6969
];
7070
replace = isArray(config.replace) ? config.replace : [];
71-
if (isString(squash))
72-
replace.push({from: squash, to: undefined});
71+
if (isString(squash)) replace.push({from: squash, to: undefined});
7372
configuredKeys = map(replace, prop("from"));
74-
return filter(defaultPolicy, function (item) {
75-
return indexOf(configuredKeys, item.from) === -1;
76-
}).concat(replace);
73+
return filter(defaultPolicy, item => configuredKeys.indexOf(item.from) === -1).concat(replace);
7774
}
7875

79-
extend(this, {
80-
id: id,
81-
type: type,
82-
location: location,
83-
array: arrayMode,
84-
squash: squash,
85-
replace: replace,
86-
isOptional: isOptional,
87-
dynamic: dynamic,
88-
config: config
89-
});
76+
extend(this, {id, type, location, squash, replace, isOptional, dynamic, config, array: arrayMode});
9077
}
9178

9279
/**

src/params/paramSet.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {extend, inherit, forEach, objectKeys, indexOf, isString} from "../common/common";
1+
import {extend, inherit, forEach, isString} from "../common/common";
22

33
import {IRawParams} from "../params/interface"
44

@@ -16,13 +16,12 @@ export default class ParamSet {
1616
}
1717

1818
$$keys() {
19-
var keys = [], chain = [], parent = this,
20-
ignore = objectKeys(ParamSet.prototype);
19+
var keys = [], chain = [], parent = this, ignore = Object.keys(ParamSet.prototype);
2120
while (parent) { chain.push(parent); parent = parent.$$parent(); }
2221
chain.reverse();
2322
forEach(chain, function(paramset) {
24-
forEach(objectKeys(paramset), function(key) {
25-
if (indexOf(keys, key) === -1 && indexOf(ignore, key) === -1) keys.push(key);
23+
forEach(Object.keys(paramset), function(key) {
24+
if (keys.indexOf(key) === -1 && ignore.indexOf(key) === -1) keys.push(key);
2625
});
2726
});
2827
return keys;

src/path/pathFactory.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {map, extend, pairs, prop, pick, omit, not, objectKeys, curry} from "../common/common";
1+
import {map, extend, pairs, prop, pick, omit, not, curry} from "../common/common";
22

33
import {runtime} from "../common/angular1";
44

@@ -60,7 +60,7 @@ export default class PathFactory {
6060
const toParamsNodeFn: (IState) => IParamsNode = PathFactory.makeParamsNode(toParams);
6161
let toPath: IParamsPath = new Path(targetState.$state().path.map(toParamsNodeFn));
6262
if (targetState.options().inherit)
63-
toPath = PathFactory.inheritParams(fromPath, toPath, objectKeys(toParams));
63+
toPath = PathFactory.inheritParams(fromPath, toPath, Object.keys(toParams));
6464
return toPath;
6565
}
6666

src/resolve/pathContext.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ResolveContext from "../resolve/resolveContext";
22
import {IState} from "../state/interface";
3-
import {objectKeys, zipObject, pick} from "../common/common";
3+
import {zipObject, pick} from "../common/common";
44

55
// TODO: Refactor!
66
// TODO: this is better named ViewContext?
@@ -24,7 +24,7 @@ export default class PathContext {
2424
var args = Array.prototype.slice.call(arguments);
2525
return zipObject(injectMe.$inject, args);
2626
};
27-
injectMe.$inject = objectKeys(pick(this._resolveContext.getResolvables(this._state), this._injector.annotate(fn)));
27+
injectMe.$inject = Object.keys(pick(this._resolveContext.getResolvables(this._state), this._injector.annotate(fn)));
2828
return this._resolveContext.invokeLater(this._state, injectMe, {}, this._options);
2929
}
3030
}

src/state/state.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {extend, defaults, copy, equalForKeys, forEach, objectKeys, ancestors, arraySearch,
1+
import {extend, defaults, copy, equalForKeys, forEach, ancestors,
22
identity, isDefined, isObject, isString} from "../common/common";
33
import Queue from "../common/queue";
44
import {IServiceProviderFactory, IPromise} from "angular";
@@ -838,7 +838,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactoryProvider) {
838838

839839
if (!isDefined(state)) return undefined;
840840
if (!isDefined(include[state.name])) return false;
841-
return params ? equalForKeys(state.params.$$values(params), $stateParams, objectKeys(params)) : true;
841+
return params ? equalForKeys(state.params.$$values(params), $stateParams, Object.keys(params)) : true;
842842
};
843843

844844

@@ -907,7 +907,7 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactoryProvider) {
907907
* @returns {Object|Array} State configuration object or array of all objects.
908908
*/
909909
$state.get = function (stateOrName: IStateOrName, base: IStateOrName): (IStateDeclaration|IStateDeclaration[]) {
910-
if (arguments.length === 0) return objectKeys(states).map(function(name) { return states[name].self; });
910+
if (arguments.length === 0) return Object.keys(states).map(function(name) { return states[name].self; });
911911
let found = matcher.find(stateOrName, base || $state.$current);
912912
return found && found.self || null;
913913
};
@@ -963,11 +963,11 @@ function $StateParamsProvider() {
963963

964964
for (let i in parents) {
965965
if (!parents[i].params) continue;
966-
parentParams = objectKeys(parents[i].params);
966+
parentParams = Object.keys(parents[i].params);
967967
if (!parentParams.length) continue;
968968

969969
for (let j in parentParams) {
970-
if (arraySearch(inheritList, parentParams[j]) >= 0) continue;
970+
if (inheritList.indexOf(parentParams[j]) >= 0) continue;
971971
inheritList.push(parentParams[j]);
972972
inherited[parentParams[j]] = this[parentParams[j]];
973973
}

src/state/stateBuilder.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {noop, extend, pick, isArray, isDefined, isFunction, isString, objectKeys, forEach} from "../common/common";
1+
import {noop, extend, pick, isArray, isDefined, isFunction, isString, forEach} from "../common/common";
22
import ParamSet from "../params/paramSet";
33
import Param from "../params/param";
44

@@ -72,7 +72,7 @@ export default function StateBuilder(root, matcher, $urlMatcherFactoryProvider)
7272
if (state[key] && !config[key]) config[key] = state[key];
7373
});
7474

75-
if (objectKeys(config).length > 0) views[name] = config;
75+
if (Object.keys(config).length > 0) views[name] = config;
7676
});
7777
return views;
7878
},

src/transition/transitionHook.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {defaults, noop, filter, not, isFunction, isDefined, objectKeys, map, pattern, isEq, val, pipe, eq, is, isPromise, isObject, parse} from "../common/common";
1+
import {defaults, noop, filter, not, isFunction, isDefined, map, pattern, isEq, val, pipe, eq, is, isPromise, isObject, parse} from "../common/common";
22
import trace from "../common/trace";
33
import {RejectFactory} from "./rejectFactory";
44
import {Transition} from "./transition";
@@ -74,7 +74,7 @@ export default class TransitionHook {
7474
* Creates Resolvable objects from the result object and adds them to the target object
7575
*/
7676
mapNewResolves(resolves: IResolveDeclarations) {
77-
let invalid = filter(resolves, not(isFunction)), keys = objectKeys(invalid);
77+
let invalid = filter(resolves, not(isFunction)), keys = Object.keys(invalid);
7878
if (keys.length)
7979
throw new Error(`Invalid resolve key/value: ${keys[0]}/${invalid[keys[0]]}`);
8080

src/url/urlMatcherFactory.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
/// <reference path='../../typings/angularjs/angular.d.ts' />
22
import {IServiceProviderFactory} from "angular";
33
import {runtime} from "../common/angular1";
4-
import {forEach, extend, inherit, map, filter, indexOf, objectKeys,
5-
isObject, isDefined, isArray, isString, isInjectable, isFunction,
6-
toJson, fromJson, identity, equals} from "../common/common";
4+
import {forEach, extend, inherit, map, filter, isObject, isDefined, isArray, isString,
5+
isInjectable, isFunction, toJson, fromJson, identity, equals} from "../common/common";
76
import matcherConfig from "./urlMatcherConfig";
87
import UrlMatcher from "./urlMatcher";
98
import Param from "../params/param";

0 commit comments

Comments
 (0)