Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Remove ref dependency from Frame #8336

Merged
merged 2 commits into from
Apr 19, 2017
Merged

Conversation

NejcZdovc
Copy link
Contributor

@NejcZdovc NejcZdovc commented Apr 15, 2017

  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Resolves #8322

Auditors: @bsclifton @bridiver

Test Plan 1

Test Plan 2

  • go to https://clifton.io and click on a inside link
  • click on back
  • check if forward is working

Test Plan 3

  • go to https://clifton.io and click on a inside link (3 different links)
  • check if long press back is working

Test Plan 4

  • go to https://clifton.io and click on a inside link (3 different links)
  • click on back 3 times
  • check if long press forward is working

@NejcZdovc NejcZdovc self-assigned this Apr 15, 2017
@NejcZdovc NejcZdovc force-pushed the hotfix/#8322-refs branch 3 times, most recently from e74bd83 to 2f512b0 Compare April 16, 2017 10:30
goBack: (state, action) => {
action = makeImmutable(action)
const tab = api.getWebContents(action.get('tabId'))
tab.goBack()
Copy link
Member

Choose a reason for hiding this comment

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

please wrap this with if (tab && !tab.isDestroyed()) { and all below as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

if (BrowserWindow.getFocusedWindow()) {
BrowserWindow.getFocusedWindow().webContents.send(messages.SHOW_CONTEXT_MENU, {
Copy link
Member

Choose a reason for hiding this comment

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

Our dispatcher now has the ability to send messages to a particular window. So it's more preferable to do an app action with a window Id specified. See for example newWebContentsAdded.

Copy link
Collaborator

Choose a reason for hiding this comment

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

actually *State.js files specifically should not use any of these apis. They should manipulate state only and avoid other dependencies to make unit testing easier. The logic you have here looks like it probably belongs in a reducer

@@ -66,7 +65,7 @@ class Navigator extends ImmutableComponent {
})
}
} else {
navAction.call(this.activeFrame)
navAction.call(this, this.props.activeTab.get('tabId'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

can use this.props.tabId to make the prop a primitive type?

Copy link
Contributor Author

@NejcZdovc NejcZdovc Apr 17, 2017

Choose a reason for hiding this comment

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

we don't have this in yet. I didn't yet implement redux here, so we have what we have for now, but when I will add redux to it, we will have primitives.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This PR only removes refs from Frame.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok, no problem

icon: history.entries[index].icon,
click: function (e) {
if (eventUtil.isForSecondaryAction(e)) {
appActions.createTabRequested({
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is also going to be a problem because you can't serialize the method call in the windowAction

@NejcZdovc NejcZdovc force-pushed the hotfix/#8322-refs branch 3 times, most recently from 7fabdb4 to 5e35810 Compare April 17, 2017 22:49
@@ -638,15 +638,15 @@ const windowActions = {
* @param {Object} frameToSkip - Properties of the frame to keep audio
*/
muteAllAudioExcept: function (frameToSkip) {
let framePropsList = windowStore.getState().get('frames')
/* let framePropsList = windowStore.getState().get('frames')
Copy link
Member

Choose a reason for hiding this comment

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

if this isn't needed anymore can it just be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is still necessary, but I need to refactor it, because if you require windowStore in appAction (you are requiring it, because I am are calling windowActions in appStore) you are getting errors. I will move this logic from windowActions into reducer, so that we don't need store here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed it in #8381

Resolves brave#8322

Auditors: @bsclifton @bridiver

Test Plan:
- tests are green
Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

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

Looks great! I'd really like to make the changes in tabs.js and change the params in contextMenuState.js. The other comments are just nits that shouldn't block merging

},

getWindowId: () => {
if (BrowserWindow.getFocusedWindow()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this should probably be a getActiveWindowId method on windows.js and return windowState.WINDOW_ID_NONE instead of -1 just for consistency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved

icon: null
}

if (url.startsWith('chrome-extension://')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this should use the appUrlUtil about page methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure which function should be used

Copy link
Collaborator

Choose a reason for hiding this comment

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

isTargetAboutUrl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}

const contextMenuState = {
setContextMenu: (state, action) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

the helpers are meant to be more general purpose so this should probably take detail as a parameter instead of action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return state
},

onLongBacHistory: (state, action) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think these two methods probably make more sense in the reducer. The state helpers are mostly just getters/setters for the state. I'm not adamantly opposed to leaving them here, but if they stay the params should be tabId, partitionNumber and history instead of action

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

* Go back in a history for a given tab
* @param {number} tabId - Tab id used for an action
*/
onNavigateBack: function (tabId) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

just a nit, but it would be more consistent to use onGoBack, onGoForward, etc...

return state
},

onLongBacHistory: (state, action) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

BacHistory -> BackHistory

@NejcZdovc NejcZdovc force-pushed the hotfix/#8322-refs branch 3 times, most recently from 38168e2 to c5e6255 Compare April 19, 2017 17:00
}

if (!entry.icon) {
entry.icon = getDefaultFaviconUrl(url)
Copy link
Collaborator

Choose a reason for hiding this comment

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

does this work correctly? It looks like we normally get it using window which isn't available here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are correct we are not receiving anything here, that's why I added if typeof undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code updated

@@ -353,7 +353,7 @@ const UrlUtil = {
* @return {string} url The base favicon URL
*/
getDefaultFaviconUrl: function (url) {
if (UrlUtil.isURL(url)) {
if (typeof window !== 'undefined' && UrlUtil.isURL(url)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can fix this by using urlParse instead of window.URL

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

@bridiver bridiver left a comment

Choose a reason for hiding this comment

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

lgtm if all the tests are passing

@NejcZdovc NejcZdovc merged commit 22dc2b2 into brave:master Apr 19, 2017
@bsclifton
Copy link
Member

++ nice cleanup! 😄

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

Successfully merging this pull request may close these issues.

5 participants