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

Refactor menu.popup #11968

Merged
merged 13 commits into from Feb 21, 2018
Merged

Refactor menu.popup #11968

merged 13 commits into from Feb 21, 2018

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Feb 20, 2018

Removes support for old way of calling menu.popup by changing signature from
(window, x, y, positioningItem) => (window, opts, callback).

Per 2.0 Breaking Changes.

Changed tests for old signature and added a few new tests.

/cc @MarshallOfSound @ckerr

@codebytere codebytere requested a review from a team February 20, 2018 02:02
Copy link
Member

@MarshallOfSound MarshallOfSound left a comment

Choose a reason for hiding this comment

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

I think I wrapped my head around this logic 😆 LGTM

// win.popup(callback)
} else {
callback = window
}
Copy link
Member

@ckerr ckerr Feb 20, 2018

Choose a reason for hiding this comment

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

Trivial change:

if (typeof window === 'function') {
  callback = window
} else {
  opts = window
}

It's weird that some of the optional arguments are in the options object but others aren't. If we were to put them all in the options, at least we wouldn't need this crazy typechecking

@codebytere codebytere requested a review from a team February 20, 2018 16:12
@@ -59,18 +59,18 @@ will become properties of the constructed menu items.

The `menu` object has the following instance methods:

#### `menu.popup([browserWindow, options, callback])`
#### `menu.popup(options)`
Copy link
Member

Choose a reason for hiding this comment

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

This refactor gets rid of so much ambiguous, confusing code. Enthusiastic 👍 on moving all the optional arguments into the options object.

[newPosition, newY, newX, newWindow] = [y, x, window, null]
}
Menu.prototype.popup = function (options) {
let {window, x, y, positionItem, callback} = options
Copy link
Member

Choose a reason for hiding this comment

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

I think this breaks? The options argument is positioningItem but this line extracts positionItem

Copy link
Member Author

Choose a reason for hiding this comment

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

ohh you're totally right

@ckerr
Copy link
Member

ckerr commented Feb 20, 2018

CI is failing because some of the sample code in electron-typescript-definitions is expecting two arguments.

@codebytere electron/typescript-definitions#95 needs review. Once that PR is merged, this popup refactor should lint cleanly

window: event.sender.getOwnerBrowserWindow(),
x: params.x,
y: params.y,
callback: callback
Copy link
Member Author

Choose a reason for hiding this comment

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

when the key is the same name as the value, you can just pass once:

menu.popup({
   window: event.sender.getOwnerBrowserWindow(),
   x: params.x,
   y: params.y,
   callback
})

@jkleinsc jkleinsc merged commit 2a97e48 into master Feb 21, 2018
@jkleinsc jkleinsc deleted the refactor-menu-popup branch February 21, 2018 19:30
facebook-github-bot pushed a commit to facebookarchive/nuclide that referenced this pull request May 18, 2018
Summary:
In Electron 2.0.0 the `menu.popup` API now only accepts options: electron/electron#11968

But this works just fine in Atom 1.25-1.27 as well, so this is a safe change.

Reviewed By: matthewwithanm

Differential Revision: D8045697

fbshipit-source-id: 9f7a3821426717998945bcf2b373710e73fdbb7f
hansonw added a commit to facebookarchive/atom-ide-ui that referenced this pull request May 18, 2018
Summary:
In Electron 2.0.0 the `menu.popup` API now only accepts options: electron/electron#11968

But this works just fine in Atom 1.25-1.27 as well, so this is a safe change.

Reviewed By: matthewwithanm

Differential Revision: D8045697

fbshipit-source-id: 9f7a3821426717998945bcf2b373710e73fdbb7f
tzarebczan added a commit to lbryio/lbry-desktop that referenced this pull request Aug 10, 2018
Breaking change in Electron 2.0
electron/electron#11968
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants