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

Convert sources reducer to ES modules #2736

Conversation

virzen
Copy link
Contributor

@virzen virzen commented Apr 25, 2017

Associated Issue: #1884

Summary of Changes

  • update sources reducer to use ES modules
  • update sources reducer test to use ES modules
  • set sources reducer's state argument's state to any to silence Flow error

Note about last point:
Without it Flow complained about missing annotation after addition of
export statement. After setting it to SourcesState it complained
about unrecognized methods, which I suspect come from Immutable.
Since this PR isn't about type-checking, I left it at any, as suggested
in this comment.

Without Flow complained about missing annotation. After setting it to
`SourcesState` it complained about unrecognized methods, which I suspect
come from Immutable and are not defined and `SourcesState`.

Since this PR isn't about type-checking, I left it at `any`.
@virzen virzen changed the title Convert sources reducer to es modules Convert sources reducer to ES modules Apr 25, 2017
@codecov
Copy link

codecov bot commented Apr 25, 2017

Codecov Report

Merging #2736 into master will decrease coverage by 0.07%.
The diff coverage is 84.61%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2736      +/-   ##
==========================================
- Coverage   60.66%   60.58%   -0.08%     
==========================================
  Files          55       55              
  Lines        2148     2144       -4     
  Branches      434      434              
==========================================
- Hits         1303     1299       -4     
  Misses        845      845
Impacted Files Coverage Δ
src/reducers/sources.js 78.22% <84.61%> (-0.69%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5b651fe...cdb2db1. Read the comment docs.

@jasonLaster
Copy link
Contributor

@virzen I haven't looked yet, but you might want to use the record<> notation for the flow issue. THe give away is immutable

@@ -44,7 +44,10 @@ const State = makeRecord(
}: SourcesState)
);

function update(state = State(), action: Action): Record<SourcesState> {
export function update(
state: any = State(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Using state: Record<SourcesState> should work.

@@ -44,7 +44,10 @@ const State = makeRecord(
}: SourcesState)
);

function update(state = State(), action: Action): Record<SourcesState> {
export function update(
state: any = State(),
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 guessing that you could replace any with Record<SourcesState>. Can you try this?

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, indeed works! 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

oops looks like I was late 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Hahaha, It's never too late :P

const makeRecord = require("../utils/makeRecord");
const { getPrettySourceURL } = require("../utils/source");
const { prefs } = require("../utils/prefs");
import * as I from "immutable";
Copy link
Contributor

Choose a reason for hiding this comment

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

We can probably use import I from "immutable";

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 seems not to be the case:

src/reducers/sources.js:11
 11: import I from "immutable";
            ^ Default import from `immutable`. This module has no default export.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh. Thanks for correction

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that's interesting. I wonder if this means we should only be importing the things we need from immutable in the future. Thanks for pointing this out and looking it up. 🥂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although there would be no significant gain in size (webpack 1.x bundles whole file anyway) I agree it's a good practice to do so. Also, it would be great for the eventual migration to webpack 2 (which features tree-shaking). 😄

Copy link
Contributor

@irfanhudda irfanhudda left a comment

Choose a reason for hiding this comment

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

Thanks @virzen

@irfanhudda irfanhudda merged commit 0eaef81 into firefox-devtools:master Apr 25, 2017
@virzen
Copy link
Contributor Author

virzen commented Apr 25, 2017

🎉 No problem!

DanUgelow pushed a commit to DanUgelow/debugger.html that referenced this pull request May 4, 2017
* Convert reducers/sources to es modules

* Convert tests for reducers/sources to es modules

* Remove type for sources reducer's state

* Set sources reducer's state argument's type to any

Without Flow complained about missing annotation. After setting it to
`SourcesState` it complained about unrecognized methods, which I suspect
come from Immutable and are not defined and `SourcesState`.

Since this PR isn't about type-checking, I left it at `any`.

* Use Record notation for sources reducer's argument type
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.

None yet

5 participants