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

Commit

Permalink
fixup 2
Browse files Browse the repository at this point in the history
- Re-use the `shallowCopy` function from core.
  • Loading branch information
gkalpak committed Jun 10, 2016
1 parent f187928 commit b24e09e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 38 deletions.
2 changes: 2 additions & 0 deletions angularFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var angularFiles = {
'src/minErr.js',
'src/Angular.js',
'src/loader.js',
'src/shallowCopy.js',
'src/stringify.js',
'src/AngularPublic.js',
'src/jqLite.js',
Expand Down Expand Up @@ -128,6 +129,7 @@ var angularFiles = {
'src/ngResource/resource.js'
],
'ngRoute': [
'src/shallowCopy.js',
'src/ngRoute/route.js',
'src/ngRoute/routeParams.js',
'src/ngRoute/directive/ngView.js'
Expand Down
26 changes: 0 additions & 26 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
includes: true,
arrayRemove: true,
copy: true,
shallowCopy: true,
equals: true,
csp: true,
jq: true,
Expand Down Expand Up @@ -933,31 +932,6 @@ function copy(source, destination) {
}
}

/**
* Creates a shallow copy of an object, an array or a primitive.
*
* Assumes that there are no proto properties for objects.
*/
function shallowCopy(src, dst) {
if (isArray(src)) {
dst = dst || [];

for (var i = 0, ii = src.length; i < ii; i++) {
dst[i] = src[i];
}
} else if (isObject(src)) {
dst = dst || {};

for (var key in src) {
if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
dst[key] = src[key];
}
}
}

return dst || src;
}


/**
* @ngdoc function
Expand Down
17 changes: 5 additions & 12 deletions src/ngRoute/route.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
'use strict';

// There are necessary for `shallowCopy()` (included via `src/shallowCopy.js`)
var isArray = angular.isArray;
var isObject = angular.isObject;

/**
* @ngdoc module
* @name ngRoute
Expand Down Expand Up @@ -39,17 +43,6 @@ function $RouteProvider() {
return angular.extend(Object.create(parent), extra);
}

function createShallowCopy(src) {
if (!angular.isObject(src)) return src;

var dst = {};
for (var key in src) {
dst[key] = src[key];
}

return dst;
}

var routes = {};

/**
Expand Down Expand Up @@ -171,7 +164,7 @@ function $RouteProvider() {
*/
this.when = function(path, route) {
//copy original route object to preserve params inherited from proto chain
var routeCopy = createShallowCopy(route);
var routeCopy = shallowCopy(route);
if (angular.isUndefined(routeCopy.reloadOnSearch)) {
routeCopy.reloadOnSearch = true;
}
Expand Down

0 comments on commit b24e09e

Please sign in to comment.