Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Factor out width-resizing logic for inline widgets into the InlineWidget base class #2285

Merged
merged 5 commits into from
Dec 11, 2012

Conversation

njx
Copy link
Contributor

@njx njx commented Dec 6, 2012

This addresses #2221 and #2218.

As part of this, cleaned up some issues around how we're doing inheritance:

  • For Should we be using Object.create() to hook up prototypes? #872, switched to using Object.create() to hook up prototypes
    (this avoids subtle bugs when binding event handlers in base classes).
  • Made it so all child classes call base class implementation for overridden functions
    (even if the base class impl is empty right now). The one exception is close(), which
    is a bit weird right now.
  • Changed the incorrect way we were using the parentClass pattern for supers--we were calling
    this.parentClass.myMethod.call(this), which doesn't work if the current method being called is on an
    intermediate class in the inheritance chain. Instead, it should be MySubclass.prototype.parentClass.myMethod.call(this).
  • In InlineColorEditor, eliminated the this.editor property in favor of using the this.hostEditor set up by the
    InlineWidget.load() method.

The issue with close() is that the base version in InlineWidget seems to assume that there is an _editorHasFocus() method on this, but InlineWidget doesn't actually define one. Need to figure out if this should be given a default implementation that just returns true. If so, then we could just eliminate close() from InlineImageWidget, and the dummy _editorHasFocus() implementation on InlineColorEditor.

…get base class.

This addresses #2221 and #2218.
As part of this, cleaned up some issues around how we're doing inheritance:
* For #872, switched to using `Object.create()` to hook up prototypes
  (this avoids subtle bugs when binding event handlers in base classes).
* Made it so all child classes call base class implementation for overridden functions
  (even if the base class impl is empty right now). The one exception is `close()`, which
  is a bit weird right now--will file a separate issue on this.
@ghost ghost assigned peterflynn Dec 6, 2012
@njx
Copy link
Contributor Author

njx commented Dec 6, 2012

@peterflynn Would you mind taking a look at this one?

@peterflynn
Copy link
Member

#2137 gives us a later opportunity to clean up the close()/_editorHasFocus() assumption -- ideally we would just eliminate the need for removeInlineWidget()'s shouldMoveFocus arg altogether, which removes the need for _editorHasFocus() and InlineImageViewer's close() override in one fell swoop.

@@ -476,7 +465,7 @@ define(function (require, exports, module) {
// Ignore when the editor's content got lost due to a deleted file
if (cause && cause.type === "deleted") { return; }
// Else yield to the parent's implementation
return this.parentClass._onLostContent.apply(this, arguments);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be less bug-prone to have all the super calls be of this form? Otherwise anyone adding a new arg in the future must remember to either add it to the call() args or switch call() to apply().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I'll fix them up.

@peterflynn
Copy link
Member

@njx: Done reviewing

@njx
Copy link
Contributor Author

njx commented Dec 11, 2012

Fixes for all comments pushed. Ready for re-review.

@njx
Copy link
Contributor Author

njx commented Dec 11, 2012

Also, I added documentation tying together all the prototypal inheritance stuff to our "Brackets Coding Conventions" page--could you review it and see if it looks good to you? https://github.com/adobe/brackets/wiki/Brackets-Coding-Conventions (near the bottom)

@@ -748,7 +748,7 @@ define(function (require, exports, module) {
},
false);
}
ContextMenu.prototype = new Menu();
ContextMenu.prototype = Object.create(Menu.prototype);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContextMenu is the only one of these that doesn't call its super constructor. But it easily could, since all Menu does is initialize this.id. Should we do that?

@peterflynn
Copy link
Member

@njx: Done re-reviewing

… assigning a new menu to this.menu, which isn't actually used).
@njx
Copy link
Contributor Author

njx commented Dec 11, 2012

Fixes pushed.

@peterflynn
Copy link
Member

Perfect, thanks for the changes. Docs on the wiki look good too. Merging...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants