-
Notifications
You must be signed in to change notification settings - Fork 58
Use native Object.assign
when available. Fixes #54.
#56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,10 @@ interface MixinArgs { | |
target: {}; | ||
} | ||
|
||
interface ObjectAssignConstructor extends ObjectConstructor { | ||
assign(target: {}, ...sources: {}[]): {} | ||
} | ||
|
||
function _mixin(kwArgs: MixinArgs): {} { | ||
const deep = kwArgs.deep; | ||
const inherited = kwArgs.inherited; | ||
|
@@ -73,14 +77,16 @@ function _mixin(kwArgs: MixinArgs): {} { | |
* @param sources Any number of objects whose enumerable own properties will be copied to the target object | ||
* @return The modified target object | ||
*/ | ||
export function assign(target: {}, ...sources: {}[]): {} { | ||
return _mixin({ | ||
deep: false, | ||
inherited: false, | ||
sources: sources, | ||
target: target | ||
}); | ||
} | ||
export const assign = has('object-assign') ? | ||
(<ObjectAssignConstructor> Object).assign : | ||
function (target: {}, ...sources: {}[]): {} { | ||
return _mixin({ | ||
deep: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just realised you are checking the has flag in line 76 and then executing code that should never be accessible because this branch shouldn't be followed if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following that logic, wouldn't your I'm usually pro-avoiding-any, but it seems like a whole lot of pointless runaround for something that ultimately doesn't matter in this case (at least as far as type information for the external API is concerned). Edit: wait, I guess it does matter, if we're assigning Object.assign directly in that case. Darnit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think we have to have it where we assign There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds fair. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Excellent! Another mistake to keep me humble! Regarding the extended type, that proposal does seem like the best way to ensure the interface is preserved. |
||
inherited: false, | ||
sources: sources, | ||
target: target | ||
}); | ||
} | ||
|
||
/** | ||
* Creates a new object from the given prototype, and copies all enumerable own properties of one or more | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should solidify the
has
naming... I know somewhere else we discussed that we would prefer to usees6-object-assign
for something like this (andobject-observe
should be [in theory]es7-object-observe
andpromise
should bees6-promise
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vaguely remember that discussion, but also vaguely remember no definitive consensus, so I decided to follow the convention already in place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it wasn't specifically directed at you, but more the wider bit reminding that we didn't close it off... I guess we can go back later and clean that up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have opened an issue in dojo/meta#5.