Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit fdcbc50

Browse files
committed
fixup 2
- Re-use the `shallowCopy` function from core.
1 parent f187928 commit fdcbc50

File tree

4 files changed

+35
-38
lines changed

4 files changed

+35
-38
lines changed

angularFiles.js

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var angularFiles = {
55
'src/minErr.js',
66
'src/Angular.js',
77
'src/loader.js',
8+
'src/shallowCopy.js',
89
'src/stringify.js',
910
'src/AngularPublic.js',
1011
'src/jqLite.js',
@@ -128,6 +129,7 @@ var angularFiles = {
128129
'src/ngResource/resource.js'
129130
],
130131
'ngRoute': [
132+
'src/shallowCopy.js',
131133
'src/ngRoute/route.js',
132134
'src/ngRoute/routeParams.js',
133135
'src/ngRoute/directive/ngView.js'

src/Angular.js

-26
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
includes: true,
5858
arrayRemove: true,
5959
copy: true,
60-
shallowCopy: true,
6160
equals: true,
6261
csp: true,
6362
jq: true,
@@ -933,31 +932,6 @@ function copy(source, destination) {
933932
}
934933
}
935934

936-
/**
937-
* Creates a shallow copy of an object, an array or a primitive.
938-
*
939-
* Assumes that there are no proto properties for objects.
940-
*/
941-
function shallowCopy(src, dst) {
942-
if (isArray(src)) {
943-
dst = dst || [];
944-
945-
for (var i = 0, ii = src.length; i < ii; i++) {
946-
dst[i] = src[i];
947-
}
948-
} else if (isObject(src)) {
949-
dst = dst || {};
950-
951-
for (var key in src) {
952-
if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
953-
dst[key] = src[key];
954-
}
955-
}
956-
}
957-
958-
return dst || src;
959-
}
960-
961935

962936
/**
963937
* @ngdoc function

src/ngRoute/route.js

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22

3+
// There are necessary for `shallowCopy()` (included via `src/shallowCopy.js`)
4+
var isArray = angular.isArray;
5+
var isObject = angular.isObject;
6+
37
/**
48
* @ngdoc module
59
* @name ngRoute
@@ -39,17 +43,6 @@ function $RouteProvider() {
3943
return angular.extend(Object.create(parent), extra);
4044
}
4145

42-
function createShallowCopy(src) {
43-
if (!angular.isObject(src)) return src;
44-
45-
var dst = {};
46-
for (var key in src) {
47-
dst[key] = src[key];
48-
}
49-
50-
return dst;
51-
}
52-
5346
var routes = {};
5447

5548
/**
@@ -171,7 +164,7 @@ function $RouteProvider() {
171164
*/
172165
this.when = function(path, route) {
173166
//copy original route object to preserve params inherited from proto chain
174-
var routeCopy = createShallowCopy(route);
167+
var routeCopy = shallowCopy(route);
175168
if (angular.isUndefined(routeCopy.reloadOnSearch)) {
176169
routeCopy.reloadOnSearch = true;
177170
}

src/shallowCopy.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
/* global: shallowCopy: true */
4+
5+
/**
6+
* Creates a shallow copy of an object, an array or a primitive.
7+
*
8+
* Assumes that there are no proto properties for objects.
9+
*/
10+
function shallowCopy(src, dst) {
11+
if (isArray(src)) {
12+
dst = dst || [];
13+
14+
for (var i = 0, ii = src.length; i < ii; i++) {
15+
dst[i] = src[i];
16+
}
17+
} else if (isObject(src)) {
18+
dst = dst || {};
19+
20+
for (var key in src) {
21+
if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
22+
dst[key] = src[key];
23+
}
24+
}
25+
}
26+
27+
return dst || src;
28+
}

0 commit comments

Comments
 (0)