@angular-wave/angular.ts 0.4.2 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +7 -7
- package/src/angular.spec.js +1 -264
- package/src/animations/animate-css-driver.js +2 -2
- package/src/animations/animate-css.js +7 -8
- package/src/animations/animate-js-driver.js +1 -3
- package/src/animations/animate-js.js +4 -4
- package/src/animations/animate-queue.js +1 -2
- package/src/animations/animation.js +3 -3
- package/src/animations/shared.js +14 -12
- package/src/core/compile/attributes.js +2 -3
- package/src/core/compile/compile.js +247 -231
- package/src/core/compile/compile.spec.js +46 -51
- package/src/core/compile/compile.test.js +1 -1
- package/src/core/interval/interval.test.js +1 -1
- package/src/core/parse/parse.js +2 -2
- package/src/core/sce/sce.js +1 -2
- package/src/core/scope/scope.js +1 -2
- package/src/directive/attrs/attrs.test.js +11 -0
- package/src/directive/attrs/boolean.html +18 -0
- package/src/directive/attrs/boolean.test.js +11 -0
- package/src/directive/attrs/element-style.html +21 -0
- package/src/directive/attrs/element-style.test.js +11 -0
- package/src/directive/bind/bing-html.spec.js +1 -1
- package/src/directive/form/form.js +12 -19
- package/src/directive/if/if.spec.js +2 -3
- package/src/directive/if/if.test.js +1 -2
- package/src/directive/include/include.js +2 -2
- package/src/directive/input/input.js +1 -2
- package/src/directive/input/input.spec.js +187 -191
- package/src/directive/list/list.js +2 -2
- package/src/directive/model/model.js +12 -17
- package/src/directive/model-options/model-options.js +22 -26
- package/src/directive/options/options.js +1 -3
- package/src/directive/options/options.spec.js +3 -4
- package/src/directive/repeat/repeat.js +2 -2
- package/src/directive/repeat/repeat.spec.js +48 -57
- package/src/directive/select/select.spec.js +9 -10
- package/src/directive/switch/switch.js +1 -2
- package/src/router/directives/state-directives.js +18 -16
- package/src/router/directives/view-directive.js +2 -2
- package/src/router/state/views.js +2 -2
- package/src/router/url/url-service.js +2 -8
- package/src/router/url/url-service.spec.js +3 -4
- package/src/services/http/http.js +5 -6
- package/src/services/http-backend/http-backend.js +19 -17
- package/src/shared/common.js +5 -8
- package/src/shared/jqlite/jqlite.js +14 -12
- package/src/shared/jqlite/jqlite.spec.js +2 -2
- package/src/shared/utils.js +15 -92
- package/types/directive/form/form.d.ts +1 -0
- package/types/shared/common.d.ts +0 -1
- package/types/shared/utils.d.ts +0 -35
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Angular } from "../../loader";
|
|
2
|
-
import { createInjector } from "../../core/di/injector";
|
|
3
2
|
import { dealoc, JQLite } from "../../shared/jqlite/jqlite";
|
|
4
|
-
import {
|
|
3
|
+
import { valueFn } from "../../shared/utils";
|
|
5
4
|
|
|
6
5
|
describe("ngRepeat", () => {
|
|
7
6
|
let element;
|
|
@@ -263,10 +262,10 @@ describe("ngRepeat", () => {
|
|
|
263
262
|
it("should track using provided function when a filter is present", () => {
|
|
264
263
|
scope.newArray = function (items) {
|
|
265
264
|
const newArray = [];
|
|
266
|
-
forEach(
|
|
265
|
+
Object.entries(items).forEach(([id, name]) => {
|
|
267
266
|
newArray.push({
|
|
268
|
-
id:
|
|
269
|
-
name:
|
|
267
|
+
id: id,
|
|
268
|
+
name: name,
|
|
270
269
|
});
|
|
271
270
|
});
|
|
272
271
|
return newArray;
|
|
@@ -519,22 +518,17 @@ describe("ngRepeat", () => {
|
|
|
519
518
|
{ name: "orange" },
|
|
520
519
|
{ name: "blonde" },
|
|
521
520
|
];
|
|
522
|
-
forEach(
|
|
523
|
-
|
|
524
|
-
(
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
{ name: "blonde" },
|
|
534
|
-
]);
|
|
535
|
-
dealoc(element);
|
|
536
|
-
},
|
|
537
|
-
);
|
|
521
|
+
["null2", "qthis", "qthisq", "fundefined", "$$parent"].forEach((name) => {
|
|
522
|
+
const expr = `item in items | filter:x as ${name} track by $index`;
|
|
523
|
+
element = $compile(`<div><div ng-repeat="${expr}"></div></div>`)(scope);
|
|
524
|
+
scope.$digest();
|
|
525
|
+
expect(scope[name]).toEqual([
|
|
526
|
+
{ name: "blue" },
|
|
527
|
+
{ name: "black" },
|
|
528
|
+
{ name: "blonde" },
|
|
529
|
+
]);
|
|
530
|
+
dealoc(element);
|
|
531
|
+
});
|
|
538
532
|
});
|
|
539
533
|
|
|
540
534
|
it("should throw if alias identifier is not a simple identifier", () => {
|
|
@@ -548,42 +542,39 @@ describe("ngRepeat", () => {
|
|
|
548
542
|
{ name: "blonde" },
|
|
549
543
|
];
|
|
550
544
|
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
dealoc(element);
|
|
585
|
-
},
|
|
586
|
-
);
|
|
545
|
+
[
|
|
546
|
+
"null",
|
|
547
|
+
"this",
|
|
548
|
+
"undefined",
|
|
549
|
+
"$parent",
|
|
550
|
+
"$root",
|
|
551
|
+
"$id",
|
|
552
|
+
"$index",
|
|
553
|
+
"$first",
|
|
554
|
+
"$middle",
|
|
555
|
+
"$last",
|
|
556
|
+
"$even",
|
|
557
|
+
"$odd",
|
|
558
|
+
"obj[key]",
|
|
559
|
+
'obj["key"]',
|
|
560
|
+
"obj['key']",
|
|
561
|
+
"obj.property",
|
|
562
|
+
"foo=6",
|
|
563
|
+
].forEach((expr) => {
|
|
564
|
+
const expression =
|
|
565
|
+
`item in items | filter:x as ${expr} track by $index`.replace(
|
|
566
|
+
/"/g,
|
|
567
|
+
""",
|
|
568
|
+
);
|
|
569
|
+
element = $compile(
|
|
570
|
+
`<div>` +
|
|
571
|
+
` <div ng-repeat="${expression}">{{item}}</div>` +
|
|
572
|
+
`</div>`,
|
|
573
|
+
)(scope);
|
|
574
|
+
expect(logs.shift().message).toMatch(/must be a valid JS identifier/);
|
|
575
|
+
|
|
576
|
+
dealoc(element);
|
|
577
|
+
});
|
|
587
578
|
});
|
|
588
579
|
|
|
589
580
|
it("should allow expressions over multiple lines", () => {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Angular } from "../../loader";
|
|
2
|
-
import { createInjector } from "../../core/di/injector";
|
|
3
2
|
import { dealoc, JQLite } from "../../shared/jqlite/jqlite";
|
|
4
|
-
import {
|
|
3
|
+
import { hashKey, equals, isNumberNaN } from "../../shared/utils";
|
|
5
4
|
import { browserTrigger } from "../../shared/test-utils";
|
|
6
5
|
|
|
7
6
|
describe("select", () => {
|
|
@@ -118,8 +117,9 @@ describe("select", () => {
|
|
|
118
117
|
const actualValues = {};
|
|
119
118
|
let optionGroup;
|
|
120
119
|
let optionValue;
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
let options = actual.find("option");
|
|
121
|
+
for (let i = 0; i < options.length; i++) {
|
|
122
|
+
let option = options[i];
|
|
123
123
|
optionGroup = option.parentNode.label || "";
|
|
124
124
|
actualValues[optionGroup] = actualValues[optionGroup] || [];
|
|
125
125
|
// IE9 doesn't populate the label property from the text property like other browsers
|
|
@@ -127,7 +127,7 @@ describe("select", () => {
|
|
|
127
127
|
actualValues[optionGroup].push(
|
|
128
128
|
option.selected ? [optionValue] : optionValue,
|
|
129
129
|
);
|
|
130
|
-
}
|
|
130
|
+
}
|
|
131
131
|
|
|
132
132
|
const message = function () {
|
|
133
133
|
return `Expected ${toJson(actualValues)} to equal ${toJson(expected)}.`;
|
|
@@ -1781,12 +1781,11 @@ describe("select", () => {
|
|
|
1781
1781
|
// reset
|
|
1782
1782
|
scope.selected = [];
|
|
1783
1783
|
scope.$digest();
|
|
1784
|
+
let elems = element.find("option");
|
|
1784
1785
|
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
});
|
|
1789
|
-
|
|
1786
|
+
for (var i = 0; i < elems.length; i++) {
|
|
1787
|
+
JQLite(elems[i])[0].selected = true;
|
|
1788
|
+
}
|
|
1790
1789
|
browserTrigger(element, "change");
|
|
1791
1790
|
|
|
1792
1791
|
const arrayVal = ["a"];
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { forEach } from "../../shared/utils";
|
|
2
1
|
import { getBlockNodes } from "../../shared/jqlite/jqlite";
|
|
3
2
|
|
|
4
3
|
export const ngSwitchDirective = [
|
|
@@ -53,7 +52,7 @@ export const ngSwitchDirective = [
|
|
|
53
52
|
ngSwitchController.cases[`!${value}`] ||
|
|
54
53
|
ngSwitchController.cases["?"])
|
|
55
54
|
) {
|
|
56
|
-
|
|
55
|
+
Object.values(selectedTranscludes).forEach((selectedTransclude) => {
|
|
57
56
|
selectedTransclude.transclude((caseElement, selectedScope) => {
|
|
58
57
|
selectedScopes.push(selectedScope);
|
|
59
58
|
const anchor = selectedTransclude.element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { tail, unnestR, uniqR, removeFrom } from "../../shared/common";
|
|
2
2
|
import { isString, isObject } from "../../shared/utils";
|
|
3
3
|
|
|
4
4
|
import { parse } from "../../shared/hof";
|
|
@@ -303,22 +303,24 @@ export function $StateRefActiveDirective(
|
|
|
303
303
|
function setStatesFromDefinitionObject(statesDefinition) {
|
|
304
304
|
if (isObject(statesDefinition)) {
|
|
305
305
|
states = [];
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
} else if (Array.isArray(stateOrName)) {
|
|
316
|
-
// If state is an array, iterate over it and add each array item individually.
|
|
317
|
-
forEach(stateOrName, function (stateOrName) {
|
|
306
|
+
Object.entries(statesDefinition).forEach(
|
|
307
|
+
([activeClass, stateOrName]) => {
|
|
308
|
+
// Helper function to abstract adding state.
|
|
309
|
+
const addStateForClass = function (stateOrName, activeClass) {
|
|
310
|
+
const ref = parseStateRef(stateOrName);
|
|
311
|
+
addState(ref.state, $scope.$eval(ref.paramExpr), activeClass);
|
|
312
|
+
};
|
|
313
|
+
if (isString(stateOrName)) {
|
|
314
|
+
// If state is string, just add it.
|
|
318
315
|
addStateForClass(stateOrName, activeClass);
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
|
|
316
|
+
} else if (Array.isArray(stateOrName)) {
|
|
317
|
+
// If state is an array, iterate over it and add each array item individually.
|
|
318
|
+
stateOrName.forEach((stateOrName) => {
|
|
319
|
+
addStateForClass(stateOrName, activeClass);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
);
|
|
322
324
|
}
|
|
323
325
|
}
|
|
324
326
|
function addState(stateName, stateParams, activeClass) {
|
|
@@ -158,7 +158,7 @@ export let ngView = [
|
|
|
158
158
|
};
|
|
159
159
|
const directive = {
|
|
160
160
|
count: 0,
|
|
161
|
-
restrict: "
|
|
161
|
+
restrict: "EA",
|
|
162
162
|
terminal: true,
|
|
163
163
|
priority: 400,
|
|
164
164
|
transclude: "element",
|
|
@@ -304,7 +304,7 @@ export function $ViewDirectiveFill(
|
|
|
304
304
|
const getControllerAs = parse("viewDecl.controllerAs");
|
|
305
305
|
const getResolveAs = parse("viewDecl.resolveAs");
|
|
306
306
|
return {
|
|
307
|
-
restrict: "
|
|
307
|
+
restrict: "EA",
|
|
308
308
|
priority: -400,
|
|
309
309
|
compile: function (tElement) {
|
|
310
310
|
const initial = tElement.html();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { pick,
|
|
1
|
+
import { pick, tail } from "../../shared/common";
|
|
2
2
|
import { isDefined, isString } from "../../shared/utils";
|
|
3
3
|
import { isInjectable } from "../../shared/predicates";
|
|
4
4
|
import { services } from "../common/coreservices";
|
|
@@ -60,7 +60,7 @@ export function ng1ViewsBuilder(state) {
|
|
|
60
60
|
}
|
|
61
61
|
const views = {},
|
|
62
62
|
viewsObject = state.views || { $default: pick(state, allViewKeys) };
|
|
63
|
-
forEach(
|
|
63
|
+
Object.entries(viewsObject).forEach(([name, config]) => {
|
|
64
64
|
// Account for views: { "": { template... } }
|
|
65
65
|
name = name || "$default";
|
|
66
66
|
// Account for views: { header: "headerComponent" }
|
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
forEach,
|
|
3
|
-
isFunction,
|
|
4
|
-
isDefined,
|
|
5
|
-
isObject,
|
|
6
|
-
isString,
|
|
7
|
-
} from "../../shared/utils";
|
|
1
|
+
import { isFunction, isDefined, isObject, isString } from "../../shared/utils";
|
|
8
2
|
import { is, pattern } from "../../shared/hof";
|
|
9
3
|
import { UrlRules } from "./url-rules";
|
|
10
4
|
import { TargetState } from "../state/target-state";
|
|
@@ -454,7 +448,7 @@ export class UrlService {
|
|
|
454
448
|
// TODO: typeof?
|
|
455
449
|
if (!isObject(object)) return false;
|
|
456
450
|
let result = true;
|
|
457
|
-
|
|
451
|
+
Object.entries(UrlMatcher.prototype).forEach(([name, val]) => {
|
|
458
452
|
if (isFunction(val))
|
|
459
453
|
result = result && isDefined(object[name]) && isFunction(object[name]);
|
|
460
454
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { dealoc } from "../../shared/jqlite/jqlite";
|
|
2
2
|
import { Angular } from "../../loader";
|
|
3
3
|
import { map, find } from "../../shared/common";
|
|
4
|
-
import { forEach } from "../../shared/utils";
|
|
5
4
|
|
|
6
5
|
describe("UrlMatcher", () => {
|
|
7
6
|
let $url;
|
|
@@ -244,7 +243,7 @@ describe("UrlMatcher", () => {
|
|
|
244
243
|
"/url/someword/child/childParam",
|
|
245
244
|
};
|
|
246
245
|
|
|
247
|
-
forEach(
|
|
246
|
+
Object.entries(shouldPass).forEach(function ([route, url]) {
|
|
248
247
|
expect($url.compile(route).exec(url, {})).toEqual({
|
|
249
248
|
childParam: "childParam",
|
|
250
249
|
matchedParam: "someword",
|
|
@@ -260,7 +259,7 @@ describe("UrlMatcher", () => {
|
|
|
260
259
|
"/url/someword/child/childParam",
|
|
261
260
|
};
|
|
262
261
|
|
|
263
|
-
forEach(
|
|
262
|
+
Object.entries(shouldThrow).forEach(function ([route, url]) {
|
|
264
263
|
expect(() => {
|
|
265
264
|
$url.compile(route).exec(url, {});
|
|
266
265
|
}).toThrowError("Unbalanced capture group in route '" + route + "'");
|
|
@@ -273,7 +272,7 @@ describe("UrlMatcher", () => {
|
|
|
273
272
|
"/url/someword/child/childParam",
|
|
274
273
|
};
|
|
275
274
|
|
|
276
|
-
forEach(
|
|
275
|
+
Object.entries(shouldPass).forEach(function ([route, url]) {
|
|
277
276
|
expect(() => {
|
|
278
277
|
$url.compile(route).exec(url, {});
|
|
279
278
|
}).not.toThrow();
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
toJson,
|
|
8
8
|
isUndefined,
|
|
9
9
|
isFunction,
|
|
10
|
-
forEach,
|
|
11
10
|
encodeUriQuery,
|
|
12
11
|
isString,
|
|
13
12
|
fromJson,
|
|
@@ -147,7 +146,7 @@ function parseHeaders(headers) {
|
|
|
147
146
|
},
|
|
148
147
|
);
|
|
149
148
|
} else if (isObject(headers)) {
|
|
150
|
-
forEach(
|
|
149
|
+
Object.entries(headers).forEach(([headerKey, headerVal]) => {
|
|
151
150
|
fillInParsed(lowercase(headerKey), trim(headerVal));
|
|
152
151
|
});
|
|
153
152
|
}
|
|
@@ -472,7 +471,7 @@ export function HttpProvider() {
|
|
|
472
471
|
let promise = $q.resolve(config);
|
|
473
472
|
|
|
474
473
|
// apply interceptors
|
|
475
|
-
forEach(
|
|
474
|
+
reversedInterceptors.forEach((interceptor) => {
|
|
476
475
|
if (interceptor.request || interceptor.requestError) {
|
|
477
476
|
requestInterceptors.unshift(
|
|
478
477
|
interceptor.request,
|
|
@@ -515,7 +514,7 @@ export function HttpProvider() {
|
|
|
515
514
|
let headerContent;
|
|
516
515
|
const processedHeaders = {};
|
|
517
516
|
|
|
518
|
-
forEach(
|
|
517
|
+
Object.entries(headers).forEach(([header, headerFn]) => {
|
|
519
518
|
if (isFunction(headerFn)) {
|
|
520
519
|
headerContent = headerFn(config);
|
|
521
520
|
if (headerContent != null) {
|
|
@@ -560,7 +559,7 @@ export function HttpProvider() {
|
|
|
560
559
|
|
|
561
560
|
// strip content-type if data is undefined
|
|
562
561
|
if (isUndefined(reqData)) {
|
|
563
|
-
|
|
562
|
+
Object.keys(headers).forEach((header) => {
|
|
564
563
|
if (lowercase(header) === "content-type") {
|
|
565
564
|
delete headers[header];
|
|
566
565
|
}
|
|
@@ -821,7 +820,7 @@ export function HttpProvider() {
|
|
|
821
820
|
function createApplyHandlers(eventHandlers) {
|
|
822
821
|
if (eventHandlers) {
|
|
823
822
|
const applyHandlers = {};
|
|
824
|
-
forEach(
|
|
823
|
+
Object.entries(eventHandlers).forEach(([key, eventHandler]) => {
|
|
825
824
|
applyHandlers[key] = function (event) {
|
|
826
825
|
if (useApplyAsync) {
|
|
827
826
|
$rootScope.$applyAsync(callEventHandler);
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { urlResolve } from "../../core/url-utils/url-utils";
|
|
2
|
-
import {
|
|
3
|
-
forEach,
|
|
4
|
-
isDefined,
|
|
5
|
-
isPromiseLike,
|
|
6
|
-
isUndefined,
|
|
7
|
-
} from "../../shared/utils";
|
|
2
|
+
import { isDefined, isPromiseLike, isUndefined } from "../../shared/utils";
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
5
|
* HTTP backend used by the {@link ng.$http service} that delegates to
|
|
@@ -51,11 +46,13 @@ export function createHttpBackend($browser) {
|
|
|
51
46
|
let abortedByTimeout = false;
|
|
52
47
|
|
|
53
48
|
xhr.open(method, url, true);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
if (headers) {
|
|
50
|
+
Object.entries(headers).forEach(([key, value]) => {
|
|
51
|
+
if (isDefined(value)) {
|
|
52
|
+
xhr.setRequestHeader(key, value);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
59
56
|
|
|
60
57
|
xhr.onload = function () {
|
|
61
58
|
const statusText = xhr.statusText || "";
|
|
@@ -105,13 +102,18 @@ export function createHttpBackend($browser) {
|
|
|
105
102
|
);
|
|
106
103
|
};
|
|
107
104
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
if (eventHandlers) {
|
|
106
|
+
eventHandlers &&
|
|
107
|
+
Object.entries(eventHandlers).forEach(([key, value]) => {
|
|
108
|
+
xhr.addEventListener(key, value);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
111
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
if (uploadEventHandlers) {
|
|
113
|
+
Object.entries(uploadEventHandlers).forEach(([key, value]) => {
|
|
114
|
+
xhr.upload.addEventListener(key, value);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
115
117
|
|
|
116
118
|
if (withCredentials) {
|
|
117
119
|
xhr.withCredentials = true;
|
package/src/shared/common.js
CHANGED
|
@@ -2,11 +2,6 @@ import { isDate, isFunction, isRegExp, isString } from "./utils";
|
|
|
2
2
|
import { all, curry } from "./hof";
|
|
3
3
|
import { services } from "../router/common/coreservices";
|
|
4
4
|
|
|
5
|
-
export function forEach(obj, cb, thisArg) {
|
|
6
|
-
if (Array.isArray(obj)) return obj.forEach(cb, thisArg);
|
|
7
|
-
Object.keys(obj).forEach((key) => cb(obj[key], key));
|
|
8
|
-
}
|
|
9
|
-
|
|
10
5
|
export function equals(o1, o2) {
|
|
11
6
|
if (o1 === o2) return true;
|
|
12
7
|
if (o1 === null || o2 === null) return false;
|
|
@@ -219,7 +214,7 @@ export function filter(collection, callback) {
|
|
|
219
214
|
const arr = Array.isArray(collection),
|
|
220
215
|
result = arr ? [] : {};
|
|
221
216
|
const accept = arr ? (x) => result.push(x) : (x, key) => (result[key] = x);
|
|
222
|
-
forEach(
|
|
217
|
+
Object.entries(collection).forEach(([i, item]) => {
|
|
223
218
|
if (callback(item, i)) accept(item, i);
|
|
224
219
|
});
|
|
225
220
|
return result;
|
|
@@ -228,7 +223,7 @@ export function filter(collection, callback) {
|
|
|
228
223
|
/** Finds an object from an array, or a property of an object, that matches a predicate */
|
|
229
224
|
export function find(collection, callback) {
|
|
230
225
|
let result;
|
|
231
|
-
forEach(
|
|
226
|
+
Object.entries(collection).forEach(([i, item]) => {
|
|
232
227
|
if (result) return;
|
|
233
228
|
if (callback(item, i)) result = item;
|
|
234
229
|
});
|
|
@@ -238,7 +233,9 @@ export function find(collection, callback) {
|
|
|
238
233
|
/** Maps an array or object properties using a callback function */
|
|
239
234
|
export function map(collection, callback, target) {
|
|
240
235
|
target = target || (Array.isArray(collection) ? [] : {});
|
|
241
|
-
|
|
236
|
+
Object.entries(collection).forEach(
|
|
237
|
+
([i, item]) => (target[i] = callback(item, i)),
|
|
238
|
+
);
|
|
242
239
|
return target;
|
|
243
240
|
}
|
|
244
241
|
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
arrayRemove,
|
|
4
4
|
concat,
|
|
5
5
|
extend,
|
|
6
|
-
forEach,
|
|
7
6
|
isDefined,
|
|
8
7
|
isFunction,
|
|
9
8
|
isObject,
|
|
@@ -103,9 +102,9 @@ export function JQLite(element) {
|
|
|
103
102
|
JQLite.prototype = {
|
|
104
103
|
toString() {
|
|
105
104
|
const value = [];
|
|
106
|
-
|
|
107
|
-
value.push(`${
|
|
108
|
-
}
|
|
105
|
+
for (var i = 0; i < this.length; i++) {
|
|
106
|
+
value.push(`${this[i]}`);
|
|
107
|
+
}
|
|
109
108
|
return `[${value.join(", ")}]`;
|
|
110
109
|
},
|
|
111
110
|
|
|
@@ -276,7 +275,7 @@ JQLite.prototype.off = function (type, fn) {
|
|
|
276
275
|
}
|
|
277
276
|
};
|
|
278
277
|
|
|
279
|
-
|
|
278
|
+
type.split(" ").forEach((type) => {
|
|
280
279
|
removeHandler(type);
|
|
281
280
|
if (MOUSE_EVENT_MAP[type]) {
|
|
282
281
|
removeHandler(MOUSE_EVENT_MAP[type]);
|
|
@@ -379,7 +378,7 @@ JQLite.prototype.val = function (value) {
|
|
|
379
378
|
// read
|
|
380
379
|
if (element.multiple && getNodeName(element) === "select") {
|
|
381
380
|
const result = [];
|
|
382
|
-
|
|
381
|
+
Array.from(element.options).forEach((option) => {
|
|
383
382
|
if (option.selected) {
|
|
384
383
|
result.push(option.value || option.text);
|
|
385
384
|
}
|
|
@@ -482,14 +481,16 @@ JQLite.prototype.replaceWith = function (arg1) {
|
|
|
482
481
|
let index;
|
|
483
482
|
const parent = element.parentNode;
|
|
484
483
|
dealoc(element);
|
|
485
|
-
|
|
484
|
+
const nodes = new JQLite(replaceNode);
|
|
485
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
486
|
+
const node = nodes[i];
|
|
486
487
|
if (index) {
|
|
487
488
|
parent.insertBefore(node, index.nextSibling);
|
|
488
489
|
} else {
|
|
489
490
|
parent.replaceChild(node, element);
|
|
490
491
|
}
|
|
491
492
|
index = node;
|
|
492
|
-
}
|
|
493
|
+
}
|
|
493
494
|
};
|
|
494
495
|
for (let i = 0; i < this.length; i++) {
|
|
495
496
|
addNodes(value, fn(this[i], arg1));
|
|
@@ -542,9 +543,10 @@ JQLite.prototype.prepend = function (node) {
|
|
|
542
543
|
const element = this[i];
|
|
543
544
|
if (element.nodeType === Node.ELEMENT_NODE) {
|
|
544
545
|
const index = element.firstChild;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
546
|
+
const el = new JQLite(node);
|
|
547
|
+
for (let i = 0; i < el.length; i++) {
|
|
548
|
+
element.insertBefore(el[i], index);
|
|
549
|
+
}
|
|
548
550
|
}
|
|
549
551
|
}
|
|
550
552
|
return this;
|
|
@@ -683,7 +685,7 @@ JQLite.prototype.triggerHandler = function (event, extraParameters) {
|
|
|
683
685
|
? [dummyEvent].concat(extraParameters)
|
|
684
686
|
: [dummyEvent];
|
|
685
687
|
|
|
686
|
-
forEach(
|
|
688
|
+
eventFnsCopy.forEach((fn) => {
|
|
687
689
|
if (!dummyEvent.isImmediatePropagationStopped()) {
|
|
688
690
|
fn.apply(element, handlerArgs);
|
|
689
691
|
}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from "./jqlite";
|
|
9
9
|
import { Angular } from "../../loader";
|
|
10
10
|
import { createInjector } from "../../core/di/injector";
|
|
11
|
-
import { equals
|
|
11
|
+
import { equals } from "../utils";
|
|
12
12
|
import { browserTrigger } from "../test-utils";
|
|
13
13
|
import { CACHE, EXPANDO } from "../../core/cache/cache";
|
|
14
14
|
|
|
@@ -902,7 +902,7 @@ describe("jqLite", () => {
|
|
|
902
902
|
});
|
|
903
903
|
|
|
904
904
|
it("should not fail on elements without the getAttribute method", () => {
|
|
905
|
-
|
|
905
|
+
[window, document].forEach((node) => {
|
|
906
906
|
expect(() => {
|
|
907
907
|
const elem = JQLite(node);
|
|
908
908
|
elem.attr("foo");
|