-
Notifications
You must be signed in to change notification settings - Fork 706
enable retention of prototypes when dragging #46
Conversation
- currently, the hack to get around lack of IE support for custom `dataTransfer` types is debilitating - practically, when items are dropped, they lose their reference and any associated prototype, because they are serialized and deserialized to and from JSON - this PR works around that by implementing a simple cache that the directives use to store and retrieve data - transferred object is always passed into event handler(s) when possible - demo `demo/advanced` is now updated to use this functionality
Thanks a lot for your pull request! The serialzation/deserialization is not due to IE support, it's how native drag & drop is supposed to work. By using a local ID you loose the ability to drag & drop from/to other browser tabs or applications (although this has to be enabled with dnd-external-sources due to IE not supporting custom mime types). Therefore, I won't merge this PR. |
That makes sense, if that's your use case. It isn't ours, however. As a general-purpose, in-browser drag/drop directive, this is by far the cleanest code I've seen out of evaluating many. So, we'll probably go ahead and maintain a fork, perhaps renamed; I'm sure you'll understand. |
(It's not my desire to maintain a fork; if you wish me to reimplement this behavior as an option, I can do that) |
It's not really my use case, I'm no longer using this directive. It just ended up with a lot of users, so I feel obliged to maintain it from time to time... Actually, your proposal to implement it as an option is worth a second thought. It's not really how the API is supposed to be used, but as long as the browsers don't implement it properly and we need workarounds anyways, we could consider it. Here are some more thoughts:
PS: It looks like you only need a subset of this directive's features, so if you want to fork it go ahead, it will definitely be easier for you ;) |
Re copying...
I'll adress your other questions and concerns tomorrow (maybe 18 hours from now or so). 😄 |
Well, currently the object is serialized, given to the native drag & drop handler of the OS, and then deserialized from the data that the OS gives us when dropped. Since it uses angular.toJSON the prototype is lost. In your first post you wrote you want to retain the reference, so that won't work with angular.copy. Also note that until angular 1.2, angular.copy is doing a deep copy of the prototype, which changes the type of the object and might make this feature useless (see angular/angular.js#1427) |
Copying objects is wrought with peril. We don't need it, so perhaps we will go with that fork idea. |
Really needed this option... I use dnd plugin for sorting an array of complex objects, so when it serializes and then deserializes them it spoils the objects totally and they become useless after dragging. It would be cool if the plugin would have really moved the objects in the array (list) without copying or serializing them. |
I'm about to add dnd-callback which will allows sidestepping the directive's dataTransfer and moving elements without serialization: 446925a |
dataTransfer
types is debilitatingdemo/advanced
is now updated to use this functionalityWithout functional tests, it's hard to say whether or not this strategy is susceptible to race conditions. We aren't targeting older browsers, but I have tested this on current versions of Chrome, Safari and Firefox, and it works in all three.