Closed
Bug 820835
Opened 13 years ago
Closed 12 years ago
Wrap all of the internal Social API objects and constants in a function scope within browser-social.js
Categories
(Firefox Graveyard :: SocialAPI, defect)
Firefox Graveyard
SocialAPI
Tracking
(Not tracked)
RESOLVED
FIXED
Firefox 22
People
(Reporter: jaws, Assigned: markh)
Details
(Whiteboard: [qa-])
Attachments
(1 file, 3 obsolete files)
5.46 KB,
patch
|
jaws
:
review+
|
Details | Diff | Splinter Review |
From #socialdev,
<gavin> hrm, I kind of managed to forget the effects of browser-social being #included in browser.js
<gavin> we're somewhat "polluting" the global window scope with things like "SharedFrame" and PANEL_MIN_HEIGHT and SocialErrorListener
<gavin> would probably be nice to wrap all that up in a function scope
Reporter | ||
Updated•13 years ago
|
Assignee: nobody → jaws
Status: NEW → ASSIGNED
Reporter | ||
Comment 1•13 years ago
|
||
This patch introduces a new global object, BrowserSocial, which encapsulates the currently used-external objects from browser-social.js. SocialMenu and SocialToolbar aren't used outside of browser-social.js, so they aren't exported.
As we talked about on IRC, this approach isn't exactly the one that you had in mind, but since I already wrote it I figured I would put it up here and see what you thought about it.
Attachment #691466 -
Flags: review?(gavin.sharp)
Reporter | ||
Comment 2•13 years ago
|
||
This version changes the name from BrowserSocial to SocialUI as requested on IRC. I'll upload a diff without the whitespace changes next.
Attachment #691466 -
Attachment is obsolete: true
Attachment #691466 -
Flags: review?(gavin.sharp)
Attachment #691480 -
Flags: review?(gavin.sharp)
Reporter | ||
Comment 3•13 years ago
|
||
Comment 4•13 years ago
|
||
Comment on attachment 691480 [details] [diff] [review]
Patch v.2
>+let SocialUI = (function () {
>+ let exports = {};
>
>-XPCOMUtils.defineLazyModuleGetter(this, "SharedFrame",
>- "resource:///modules/SharedFrame.jsm");
>+ // The minimum sizes for the auto-resize panel code.
>+ const PANEL_MIN_HEIGHT = 100;
>+ const PANEL_MIN_WIDTH = 330;
How about:
let SocialUI = {
PANEL_MIN_HEIGHT: 100,
PANEL_MIN_WIDTH: 330,
etc.
Wrapping everything in a function and returning an object that you're incrementally building seems like playing with language features that we don't really need here.
Comment 5•13 years ago
|
||
(In reply to Dão Gottwald [:dao] from comment #4)
> How about:
>
> let SocialUI = {
> PANEL_MIN_HEIGHT: 100,
> PANEL_MIN_WIDTH: 330,
> etc.
That makes it more annoying to use these (need this.PANEL_MIN_HEIGHT, and to make sure you have the right "this", etc.). I think the goal should be to avoid changing the code as much as possible, but also avoid leaking all this random stuff into the window scope.
I don't much like leading caps for non-global property names, so I'd prefer SocialUI.chatBar over SocialUI.ChatBar.
It's a bit confusing to have the "primary" objects just all mixed in with various little helper functions, but I'm not sure I see a great way to avoid that. I guess maybe it would help to define "exports" in one place, rather than piece-by-piece, so it's more obvious what the exported properties are.
Comment 6•13 years ago
|
||
(In reply to :Gavin Sharp (use gavin@gavinsharp.com for email) from comment #5)
> (In reply to Dão Gottwald [:dao] from comment #4)
> > How about:
> >
> > let SocialUI = {
> > PANEL_MIN_HEIGHT: 100,
> > PANEL_MIN_WIDTH: 330,
> > etc.
>
> That makes it more annoying to use these (need this.PANEL_MIN_HEIGHT, and to
> make sure you have the right "this", etc.). I think the goal should be to
> avoid changing the code as much as possible, but also avoid leaking all this
> random stuff into the window scope.
Each of these two constants are used once or twice; they shouldn't dictate how we organize 1000+ lines of code. The anonymous function is only really useful if you want to hide code from the outside, i.e. if you have lots of stuff that you don't want to "export", but I'm not sure why that would be preferable over just using the underscore prefix, which is less magic, results in a simpler code structure and makes "private" stuff more obvious when reading the code.
Reporter | ||
Updated•13 years ago
|
Attachment #691480 -
Flags: review?(gavin.sharp)
Reporter | ||
Comment 7•13 years ago
|
||
I ran into some weird issue when wrapping the entire file in a function block and then defining the exported objects on |window|. I probably had the same issue with the other patch, but my build system wasn't working as I expected and so I wasn't seeing the issue before.
Assignee: jaws → nobody
Status: ASSIGNED → NEW
Assignee | ||
Comment 8•12 years ago
|
||
This patch is very simple - it just declares the stuff we care about outside the function scope, so assignments to them within the function do the right thing. Tests all pass.
Attachment #729403 -
Flags: feedback?(jAwS)
Reporter | ||
Updated•12 years ago
|
Attachment #729403 -
Flags: feedback?(jAwS) → review+
Reporter | ||
Updated•12 years ago
|
Attachment #691480 -
Attachment is obsolete: true
Reporter | ||
Updated•12 years ago
|
Attachment #691482 -
Attachment is obsolete: true
Reporter | ||
Updated•12 years ago
|
Assignee: nobody → mhammond
Status: NEW → ASSIGNED
Assignee | ||
Comment 9•12 years ago
|
||
Comment 10•12 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 22
Updated•6 years ago
|
Product: Firefox → Firefox Graveyard
You need to log in
before you can comment on or make changes to this bug.
Description
•