Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Draggable/Droppable handling via getters & setters #1996

Open
tejaede opened this issue Aug 9, 2018 · 0 comments
Open

Implement Draggable/Droppable handling via getters & setters #1996

tejaede opened this issue Aug 9, 2018 · 0 comments

Comments

@tejaede
Copy link
Collaborator

tejaede commented Aug 9, 2018

The registration/unregistration of Component#droppable and Component#draggable is currently handled via property change listeners:

https://github.com/montagejs/montage/blob/master/ui/component.js#L1848-L1849

 this.addOwnPropertyChangeListener("draggable", this);
 this.addOwnPropertyChangeListener("droppable", this);

https://github.com/montagejs/montage/blob/master/ui/component.js#L2936-L2954

    handleDraggableChange: {
        value: function (value) {
            if (value) {
                this.registerDraggable();
            } else {
                this.unregisterDraggable();
            }
        }
    },

    handleDroppableChange: {
        value: function (value) {
            if (value) {
                this.registerDroppable();
            } else {
                this.unregisterDroppable();
            }
        }
    },

This prevents a developer from having these properties themselves unless they override the handlers.
E.g.

draggable: {
   get: function () {
        //My own draggable logic
   },
   set: function (value) {
        //My own draggable logic
   }
},

//Required to prevent default drag functionality.
handleDraggableChange: {
      value: function () {}
}

This broke backwards compatibility in an existing component of ours. Is there a reason that draggable and droppable can't be handled via getters and setters? If there is a compelling one, we can fix this ourselves in using the strategy above. However, if there is not, I vote they be converted to getters/setters. E.g.

draggable: {
   get: function () {
        return this._draggable;
   },
   set: function (value) {
        if (this._draggable !== value) {
            if (value) {
                this.registerDroppable();
            } else {
                this.unregisterDroppable();
            }
            this._draggable = value;
        }
   }
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants