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

Adds TS support #253

Merged
merged 9 commits into from
Jul 17, 2018
Merged

Adds TS support #253

merged 9 commits into from
Jul 17, 2018

Conversation

NejcZdovc
Copy link
Contributor

@NejcZdovc NejcZdovc commented Jul 13, 2018

Resolves brave/brave-browser#559

Submitter Checklist:

  • 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).
  • Tagged reviewers and labelled the pull request as needed.
  • Request a security/privacy review as needed.

Test Plan:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions

@NejcZdovc NejcZdovc self-assigned this Jul 13, 2018
@NejcZdovc NejcZdovc force-pushed the ts branch 3 times, most recently from c55c091 to a36c79a Compare July 16, 2018 05:43
@NejcZdovc NejcZdovc requested review from bbondy and cezaraugusto July 16, 2018 11:47
@NejcZdovc NejcZdovc changed the title WIP: Adds TS support Adds TS support Jul 16, 2018
@bbondy bbondy requested a review from yrliou July 16, 2018 18:32
Copy link
Member

@yrliou yrliou left a comment

Choose a reason for hiding this comment

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

LGTM, just a nit below.


export const NumBlockedStat = (props: Props) => (
<div>
<span i18n-content='adsBlocked'/> {props.adsBlockedStat || 0}
Copy link
Member

Choose a reason for hiding this comment

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

is || 0 still required 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.

no we can remove it

@NejcZdovc NejcZdovc merged commit fdbbe4e into master Jul 17, 2018
Copy link
Contributor

@cezaraugusto cezaraugusto left a comment

Choose a reason for hiding this comment

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

comments left

// Utils
import * as storage from '../storage'

const adblockReducer: Reducer<AdBlock.State | undefined> = (state: AdBlock.State | undefined, action) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we allowing an undefined state here? maybe setting a default state or empty object would be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Redux will send you undefined state in when you combine reducers https://github.com/reduxjs/redux/blob/9b43c56b98cc75505e161b8e26c18240fa99b184/src/combineReducers.js#L68. For every reducer we have check in the beginning for undefined. I am planing of improving this, so that we would will actually set state when redux send INIT in

if (state === undefined) {
state = storage.load() || {}
state = Object.assign(storage.getInitialState(), state)
state = storage.load()
Copy link
Contributor

Choose a reason for hiding this comment

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

having a fallback to {} seemed a good guard against undefined values not sure why was 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.

Load can't send undefined so that's why it was removed. If we add guard then we need to allow empty object on state as well

const starIcon = isBookmarked ? 'fa-star' : 'fa-star-o'
const pinIcon = isPinned ? 'fa-minus' : 'fa-thumb-tack'

return connectDragSource(connectDropTarget(
<div className='topSiteSquareSpace'>
<div
className='topSitesElement'
style={{
opacity: opacity
Copy link
Contributor

Choose a reason for hiding this comment

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

was this removed on purpose?

}, () => {
fetchBookmarkInfo(action.url)
})
const topSite: NewTab.Site | undefined = state.topSites.find((site) => site.url === action.url)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm often seeing this pattern and wondering if we can find a better way to block undefined values via TS so it can warn us when something is wrong? Isn't this bypassing empty state values?

if (state === undefined) {
state = storage.load() || {}
state = Object.assign(storage.getInitialState(), state)
state = storage.load()
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above comment having a fallback to {} seemed a good guard against undefined values. please educate me if this is not need for some reason

if (state === undefined) {
state = storage.load() || {}
state = Object.assign(storage.getInitialState(), state)
state = storage.load()
Copy link
Contributor

Choose a reason for hiding this comment

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

same as previous comment regarding fallback

@@ -30,7 +26,7 @@ module.exports = {
rules: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
loader: 'ts-loader'
Copy link
Contributor

Choose a reason for hiding this comment

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

is ts-loader just better than awesome-typescript-loader? wondering in case we should use it in brave-ui too

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 had quite some problems with awesome loader, because of brave-browser -> brave-core relation and files were not found. With ts-loader everything is working ok

"tslint": "^5.8.0",
"tslint-config-standard": "^7.0.0",
"tslint-react": "^3.2.0",
"typescript": "^2.8.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

we have these deps required in brave-browser as well, is the duplicate necessary? I'd like to have them here instead of the former as they're only for webUI and it's easier to review changes in one PR. I don't think they're needed in both places but cc @bbondy in case we need both

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 would like to have it live only in brave-core, because here an actual logic is and it' needed here because of travis, but the problem is that we are triggering builds from brave-browser repo. I think that we would need to change this logic and instead of triggering it from brave-browser webpack should be triggered directly from brave-core. Let me try it and see if I will be successful

@@ -0,0 +1,28 @@
{
"compilerOptions": {
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above comment not sure if we need two tsconfig files this could lead to weird bugs in case we update only one and build is unsure which one to request

Copy link
Contributor Author

Choose a reason for hiding this comment

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

comment left above

@bbondy bbondy deleted the ts branch August 23, 2018 13:40
cezaraugusto pushed a commit that referenced this pull request Jul 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants