Added Flow Typing #778

Merged
liamcardenas merged 9 commits from flowtype into master 2017-12-01 01:03:47 +01:00
liamcardenas commented 2017-11-22 23:39:48 +01:00 (Migrated from github.com)

Not ready for review yet

  • Add flow to project
  • Integrate with traditional webpack flow
  • Allow background flow daemon to run w/o webpack integration (crossing out because I am waiting until watch.sh refactor is completed)
  • Add standards and documentation for using flow
  • Add example typed file/component (maybe this will be in conjunction with the immutable js integration)
Not ready for review yet - [x] Add flow to project - [x] Integrate with traditional webpack flow - [x] ~~Allow background flow daemon to run w/o webpack integration (crossing out because I am waiting until watch.sh refactor is completed)~~ - [ ] Add standards and documentation for using flow - [x] Add example typed file/component (maybe this will be in conjunction with the immutable js integration)
neb-b (Migrated from github.com) reviewed 2017-11-30 00:01:16 +01:00
@ -0,0 +20,4 @@
function flowErrorCode(status) {
var error;
switch (status) {
neb-b (Migrated from github.com) commented 2017-11-30 00:01:16 +01:00

Maybe add a link to flow docs for each of these cases?

Maybe add a link to flow docs for each of these cases?
neb-b (Migrated from github.com) reviewed 2017-11-30 00:02:13 +01:00
@ -0,0 +75,4 @@
function checkFlowStatus(compiler, next) {
var res = spawnSync(flow, store.flowOptions);
neb-b (Migrated from github.com) commented 2017-11-30 00:02:13 +01:00

I think we should try to use let and const to show if a variable will change or not

I think we should try to use `let` and `const` to show if a variable will change or not
kauffj (Migrated from github.com) reviewed 2017-11-30 00:03:14 +01:00
kauffj (Migrated from github.com) left a comment

Comments.

Comments.
kauffj (Migrated from github.com) commented 2017-11-29 23:53:40 +01:00

thoughts on all upper case for types?

thoughts on all upper case for types?
kauffj (Migrated from github.com) commented 2017-11-29 23:54:20 +01:00

Any particular reason are these optional properties that we don't set on defaultState? IMO optional properties should generally be avoided.

Any particular reason are these optional properties that we don't set on `defaultState`? IMO optional properties should generally be avoided.
kauffj (Migrated from github.com) commented 2017-11-29 23:54:53 +01:00

(also, state types will generally need to be exported so they can be used by selectors)

(also, state types will generally need to be exported so they can be used by selectors)
kauffj (Migrated from github.com) commented 2017-11-29 23:59:13 +01:00

Isn't this just ?string

Isn't this just `?string`
kauffj (Migrated from github.com) commented 2017-11-30 00:00:50 +01:00

Isn't this an unsealed Object or null? (not clear on Flow syntax for this: ?{}?)

Isn't this an unsealed `Object` or `null`? (not clear on Flow syntax for this: `?{}`?)
kauffj (Migrated from github.com) commented 2017-11-30 00:02:11 +01:00

If this is the return value for an interval call, I believe it is ?number

If this is the return value for an interval call, I believe it is `?number`
kauffj (Migrated from github.com) commented 2017-11-30 00:02:58 +01:00

I don't remember what's put in this but I'm just hating on all of your usage of mixed at this point.

I don't remember what's put in this but I'm just hating on all of your usage of `mixed` at this point.
@ -14,3 +44,3 @@
upgradeSkipped: sessionStorage.getItem("upgradeSkipped"),
upgradeSkipped: sessionStorage.getItem("upgradeSkipped") === "true",
daemonVersionMatched: null,
daemonReady: false,
kauffj (Migrated from github.com) commented 2017-11-29 23:56:38 +01:00

Can you clarify this change?

(And btw, we want to be killing this storage pattern)

Can you clarify this change? (And btw, we want to be killing this storage pattern)
neb-b (Migrated from github.com) reviewed 2017-11-30 00:03:26 +01:00
neb-b (Migrated from github.com) commented 2017-11-30 00:03:25 +01:00

We should have an action type

We should have an `action` type
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:05:46 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 00:05:45 +01:00

I believe mixed is the correct way for to indicate Object

I believe mixed is the correct way for to indicate Object
kauffj (Migrated from github.com) reviewed 2017-11-30 00:06:02 +01:00
kauffj (Migrated from github.com) commented 2017-11-30 00:06:02 +01:00

Also also, this should be a sealed object.

Also also, this should be a sealed object.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:08:24 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 00:08:24 +01:00

optional properties can be thought of as implicitly there, but set to "undefined". I am more than happy to add them, though.

The one edge case I could see, and I will double check this, is, as I was saying in slack:

downloadProgress?: number could be a number or undefined
downloadProgress: ?number could be a number or undefined or null

In order to remove optional fields, we would have to either allow null or determine a non-null default value for each field.

optional properties can be thought of as implicitly there, but set to "undefined". I am more than happy to add them, though. The one edge case I could see, and I will double check this, is, as I was saying in slack: downloadProgress?: number could be a number or undefined downloadProgress: ?number could be a number or undefined or null In order to remove optional fields, we would have to either allow null or determine a non-null default value for each field.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:09:13 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 00:09:13 +01:00

me too, i'll figure it out

me too, i'll figure it out
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:10:31 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 00:10:31 +01:00

I agree, I meant to bring this up, we also need to figure out how to properly do naming.

I agree, I meant to bring this up, we also need to figure out how to properly do naming.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:11:36 +01:00
@ -0,0 +75,4 @@
function checkFlowStatus(compiler, next) {
var res = spawnSync(flow, store.flowOptions);
liamcardenas (Migrated from github.com) commented 2017-11-30 00:11:36 +01:00

this file contains code from another repo, I don't want to change it too much because, once they update their npm package, we will be able to use that instead of this file.

this file contains code from another repo, I don't want to change it too much because, once they update their npm package, we will be able to use that instead of this file.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:13:19 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 00:13:19 +01:00

ah i didn't realize that, thanks.

ah i didn't realize that, thanks.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:14:25 +01:00
@ -14,3 +44,3 @@
upgradeSkipped: sessionStorage.getItem("upgradeSkipped"),
upgradeSkipped: sessionStorage.getItem("upgradeSkipped") === "true",
daemonVersionMatched: null,
daemonReady: false,
liamcardenas (Migrated from github.com) commented 2017-11-30 00:14:25 +01:00

sessionStorage.getItem("upgradeSkipped") returns the string: "true" so this is, essentailly, casting it to a boolean.

`sessionStorage.getItem("upgradeSkipped")` returns the string: `"true"` so this is, essentailly, casting it to a boolean.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:14:56 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 00:14:56 +01:00

yes, thanks

yes, thanks
liamcardenas (Migrated from github.com) reviewed 2017-11-30 00:16:17 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 00:16:17 +01:00

completely agreed, I'm trying to figure that out now

There is some cool stuff we can do with flow and actions, but I also don't want to introduce too much unnecessary boilerplate if its not going to practically help us catch errors

completely agreed, I'm trying to figure that out now There is some cool stuff we can do with flow and actions, but I also don't want to introduce too much unnecessary boilerplate if its not going to practically help us catch errors
liamcardenas (Migrated from github.com) reviewed 2017-11-30 08:00:55 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 08:00:34 +01:00

I am going to go through each of these one by one to determine whether or not I can add null, or some other initial value to them instead of undefined, however, there inevitably will be some fields that are initialized as undefined (given what we decided in terms of having no optional types + using undefined as a distinct value). Does this seem alright to you guys? @kauffj @seanyesmunt

I am going to go through each of these one by one to determine whether or not I can add null, or some other initial value to them instead of undefined, however, there inevitably will be some fields that are initialized as undefined (given what we decided in terms of having no optional types + using undefined as a distinct value). Does this seem alright to you guys? @kauffj @seanyesmunt
kauffj (Migrated from github.com) reviewed 2017-11-30 17:49:57 +01:00
kauffj (Migrated from github.com) commented 2017-11-30 17:49:57 +01:00

Yes, given that the existing behavior a property not explicitly set on defaultState is to default to undefined, it makes sense to set values to undefined rather than null to match existing behavior.

Yes, given that the existing behavior a property not explicitly set on `defaultState` is to default to `undefined`, it makes sense to set values to `undefined` rather than `null` to match existing behavior.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 18:05:54 +01:00
liamcardenas (Migrated from github.com) commented 2017-11-30 18:05:54 +01:00

Got it. Makes sense. I'm cool with this.

Got it. Makes sense. I'm cool with this.
kauffj (Migrated from github.com) reviewed 2017-11-30 21:06:59 +01:00
@ -14,3 +44,3 @@
upgradeSkipped: sessionStorage.getItem("upgradeSkipped"),
upgradeSkipped: sessionStorage.getItem("upgradeSkipped") === "true",
daemonVersionMatched: null,
daemonReady: false,
kauffj (Migrated from github.com) commented 2017-11-30 21:06:59 +01:00

@liamcardenas but this changeset also changes this value from true to "true".

(If you just want to cast, I'd propose either a typical cast of Boolean(foo) or !!foo)

@liamcardenas but this changeset also changes this value from `true` to `"true"`. (If you just want to cast, I'd propose either a typical cast of `Boolean(foo)` or `!!foo`)
neb-b (Migrated from github.com) reviewed 2017-11-30 23:22:47 +01:00
neb-b (Migrated from github.com) left a comment

Just some questions on the flowtype-plugin.js file, but looks good.

Just some questions on the `flowtype-plugin.js` file, but looks good.
@ -0,0 +75,4 @@
function checkFlowStatus(compiler, next) {
var res = spawnSync(flow, store.flowOptions);
neb-b (Migrated from github.com) commented 2017-11-30 23:19:43 +01:00

What is the other module? Seems simple enough, do we need to use it?

What is the other module? Seems simple enough, do we need to use it?
@ -14,3 +44,3 @@
upgradeSkipped: sessionStorage.getItem("upgradeSkipped"),
upgradeSkipped: sessionStorage.getItem("upgradeSkipped") === "true",
daemonVersionMatched: null,
daemonReady: false,
neb-b (Migrated from github.com) commented 2017-11-30 23:21:54 +01:00

I think he's saying no matter how it was stored in sessionStorage it was still being returned as "true".

Using the !! operator or Boolean will still return true for "false" strings because strings are truthy.

@liamcardenas is that right?

I think he's saying no matter how it was stored in `sessionStorage` it was still being returned as `"true"`. Using the `!!` operator or `Boolean` will still return `true` for `"false"` strings because strings are truthy. @liamcardenas is that right?
liamcardenas (Migrated from github.com) reviewed 2017-11-30 23:26:07 +01:00
@ -14,3 +44,3 @@
upgradeSkipped: sessionStorage.getItem("upgradeSkipped"),
upgradeSkipped: sessionStorage.getItem("upgradeSkipped") === "true",
daemonVersionMatched: null,
daemonReady: false,
liamcardenas (Migrated from github.com) commented 2017-11-30 23:26:07 +01:00

that doesn't work, because Boolean('false') and !!'false' evaluate to true

This is the best way to get a boolean value that is recorded as a string. The alternative would be JSON.parse(foo), but I wouldn't want to be able to introduce arbitrary, non-boolean values.

that doesn't work, because `Boolean('false')` and `!!'false'` evaluate to `true` This is the best way to get a boolean value that is recorded as a string. The alternative would be `JSON.parse(foo)`, but I wouldn't want to be able to introduce arbitrary, non-boolean values.
kauffj (Migrated from github.com) reviewed 2017-11-30 23:32:42 +01:00
kauffj (Migrated from github.com) commented 2017-11-30 23:32:42 +01:00

@liamcardenas I do not think that is correct https://flow.org/en/docs/types/mixed/

@liamcardenas I do not think that is correct https://flow.org/en/docs/types/mixed/
kauffj (Migrated from github.com) reviewed 2017-11-30 23:36:54 +01:00
@ -14,3 +44,3 @@
upgradeSkipped: sessionStorage.getItem("upgradeSkipped"),
upgradeSkipped: sessionStorage.getItem("upgradeSkipped") === "true",
daemonVersionMatched: null,
daemonReady: false,
kauffj (Migrated from github.com) commented 2017-11-30 23:36:54 +01:00

Wow, sure enough, the Storage API changes the type!

window.sessionStorage.setItem("foo", true);
undefined
window.sessionStorage.getItem("foo");
"true"

Absolute insanity!

Wow, sure enough, the Storage API changes the type! ``` window.sessionStorage.setItem("foo", true); undefined window.sessionStorage.getItem("foo"); "true" ``` Absolute insanity!
liamcardenas (Migrated from github.com) reviewed 2017-11-30 23:43:54 +01:00
@ -14,3 +44,3 @@
upgradeSkipped: sessionStorage.getItem("upgradeSkipped"),
upgradeSkipped: sessionStorage.getItem("upgradeSkipped") === "true",
daemonVersionMatched: null,
daemonReady: false,
liamcardenas (Migrated from github.com) commented 2017-11-30 23:43:54 +01:00

I know, I wouldn't have caught this if flow didn't give me a type error for trying to input/expect booleans where it is supposed to be a string.

That's the beauty of type checking, this could've led to some pretty nasty bugs.

I know, I wouldn't have caught this if flow didn't give me a type error for trying to input/expect booleans where it is supposed to be a string. That's the beauty of type checking, this could've led to some pretty nasty bugs.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 23:46:39 +01:00
@ -0,0 +75,4 @@
function checkFlowStatus(compiler, next) {
var res = spawnSync(flow, store.flowOptions);
liamcardenas (Migrated from github.com) commented 2017-11-30 23:46:39 +01:00

this is a pretty decently maintained package: https://github.com/zhirzh/flow-babel-webpack-plugin

I'd like to be able to include other changes made by that developer if possible. I left an issue about updating the NPM package. If it looks abandoned after enough time then we should look at bringing this in-house. I expect to deprecate this file relatively soon though.

this is a pretty decently maintained package: https://github.com/zhirzh/flow-babel-webpack-plugin I'd like to be able to include other changes made by that developer if possible. I left an issue about updating the NPM package. If it looks abandoned after enough time then we should look at bringing this in-house. I expect to deprecate this file relatively soon though.
liamcardenas (Migrated from github.com) reviewed 2017-11-30 23:47:13 +01:00
@ -0,0 +75,4 @@
function checkFlowStatus(compiler, next) {
var res = spawnSync(flow, store.flowOptions);
liamcardenas (Migrated from github.com) commented 2017-11-30 23:47:13 +01:00

but you're right, if need be it is definitely simple

but you're right, if need be it is definitely simple
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: LBRYCommunity/lbry-desktop#778
No description provided.