-
Notifications
You must be signed in to change notification settings - Fork 62
lang needs something that Just Works for simple value copying #26
Comments
I just took a look at it, maybe should have before... That isn't really a usable API in my opinion. To do the most basic with it, you have to do this: let copy = lang.copy({ sources: [ orig ] }); Wow! I mean of course I could have done this, in most cases: let copy = Object.create(orig); Some of the functionality in the export function copy(...sources: any[]): any;
export function copyDeep(...sources: any[]): any; I also don't understand the use case where we wouldn't want to copy descriptors. I could see there maybe variations in how we determine what keys to copy over, but why would we not copy the descriptor? |
Looks like @kfranqueiro specific use case in this is interesting... The challenge is the a ClientRec instances has no own properties. All the properties are in the prototype and they are all "odd". Looking at |
Based on some further conversations offline between @bryanforbes and @kfranqueiro I am not seeing a ClientRec instance with own keys in Chrome (43) (nor Firefox). Here is a JSFiddle I have been playing with. |
First off, That said, there are admittedly some things here that are confusing. For example, the current package also has an Dojo 1's |
We should align the lang features to the Object.assign in my opinion, and whatever behaviour is the behaviour of ES6 should be the starting point. Having additional functionality, we should build upon Object.assign. I haven't looked at the shim, yet, but if it is fully compatible with ES6, it is supposed to be handling a lot of the edge cases we are running into. |
I believe we should have 4 functions: |
Sounds like a good idea... What about a Also, we should probably be explicit about how accessor descriptors, enumeration, own properties and the prototype are handled in copy. I suspect some of these are "implied" in the above, but I will admit, I don't have them fully delineated in my head at the moment. If I get a moment, I will write down what is knocking in my head. |
The Dojo 2 Core proposal does include both
As for the difference between |
I know we are already mulling over how to split up
lang.copy
to simplify its API and also the mental overhead regarding the combinations it supports. On top of that, one thing it doesn't seem to support is simply copying values, a lalang.mixin
in Dojo 1.Here's an interesting (though probably rather edgy) case I just ran into (trying to use it during development of
dom/geometry
, dojo/dom#8) that affects various browsers differently, presumably due to how they treat nativeClientRect
objects:ClientRect
object viasomeElement.getBoundingClientRect()
copy
Results:
Tangentially, I would definitely vouch for not burying
sources
in akwArgs
object if we can help it, and accommodating one source without needing an array. Having to do that in this case seems rather obtuse. (I realize that other derivative APIs likecreate
andduplicate
wrap this complexity away.)The text was updated successfully, but these errors were encountered: