Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CHORE] remove all usage of Ember.copy
fix package.json support IE11 (cherry picked from commit 23a87e8)
- Loading branch information
Showing
10 changed files
with
105 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* global WeakMap */ | ||
export default function deepCopy(obj) { | ||
return _deepCopy(obj, new WeakMap()); | ||
} | ||
|
||
function isPrimitive(value) { | ||
return typeof value !== 'object' || value === null; | ||
} | ||
|
||
function _deepCopy(oldObject, seen) { | ||
if (Array.isArray(oldObject)) { | ||
return copyArray(oldObject, seen); | ||
} else if (!isPrimitive(oldObject)) { | ||
return copyObject(oldObject, seen); | ||
} else { | ||
return oldObject; | ||
} | ||
} | ||
|
||
function copyObject(oldObject, seen) { | ||
let newObject = {}; | ||
|
||
Object.keys(oldObject).forEach(key => { | ||
let value = oldObject[key]; | ||
let newValue = isPrimitive(value) ? value : seen.get(value); | ||
|
||
if (value && newValue === undefined) { | ||
newValue = newObject[key] = _deepCopy(value, seen); | ||
seen.set(value, newValue); | ||
} | ||
|
||
newObject[key] = newValue; | ||
}); | ||
|
||
return newObject; | ||
} | ||
|
||
function copyArray(oldArray, seen) { | ||
let newArray = []; | ||
|
||
for (let i = 0; i < oldArray.length; i++) { | ||
let value = oldArray[i]; | ||
let newValue = isPrimitive(value) ? value : seen.get(value); | ||
|
||
if (value && newValue === undefined) { | ||
newValue = newArray[i] = _deepCopy(value, seen); | ||
seen.set(value, newValue); | ||
} | ||
|
||
newArray[i] = newValue; | ||
} | ||
|
||
return newArray; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.