Skip to content

Conversation

@seanf
Copy link
Collaborator

@seanf seanf commented Jan 14, 2018

Sorry, this proved a little larger than expected!

It's mostly refactoring to avoid a cast, to separate JSX from defineMessages and from formatMessage (fewer ifs), and to use more meaningful names.

But to avoid casting the PropertyAssignment's PropertyName as any I had to use text instead of escapedText (I think escapedText must be non-public compiler API), so we now use the un-escaped text as the message key (which seems like the right thing to do).

Also, I changed things a bit so that the object keys for defineMessages/formatMessage can now be string/number literals, not just identifiers.

It should be mostly logical if you read the commits in order, but let me know if you want it split up or something.

@seanf
Copy link
Collaborator Author

seanf commented Jan 14, 2018

Also added tslint and followed most of its suggestions.

@BANG88
Copy link
Owner

BANG88 commented Jan 14, 2018

@seanf do you mind that i invite you as a collaborator ?

@BANG88
Copy link
Owner

BANG88 commented Jan 14, 2018

@seanf Thank you so much. Awesome refactor..

@BANG88 BANG88 merged commit 40f0ba1 into BANG88:master Jan 14, 2018
@seanf seanf deleted the refactor branch January 14, 2018 10:16
@seanf
Copy link
Collaborator Author

seanf commented Jan 14, 2018

@seanf Thank you so much. Awesome refactor..

Thanks!

@seanf do you mind that i invite you as a collaborator ?

@BANG88 not at all! But please give me some guidance on what I should do (eg with my own code, or with others' pull requests). I think it's always good to have a second person review any code.

* @param {string} contents
* @returns {array}
*/
// TODO perhaps we should expose the Message interface
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@BANG88 How would you feel about exposing the Message interface as the return type for the (publicly exported) main method (well, an array of them to be exact)? (As opposed to an array of plain object {}.)

It shouldn't break any consumers, because I believe it's a narrower type, but I'm still very new to TypeScript, so I could be wrong about that. In practice the consumers seem to be plain JavaScript npm scripts (unless they use ts-node), so they probably don't care about types. Still, I like types as documentation.

Copy link
Owner

Choose a reason for hiding this comment

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

I like the types too. If you prefer or think is useful for you please do it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thinking about it a bit more, I think it would be better if the interface looked more like this:

interface MessageDescriptor {
  id: string
  defaultMessage: string
  description?: string
  [key: string]: string; // for any other properties
}

Otherwise exposing it won't really add much value.

"rules": {
"no-any": true,
// TODO perhaps we *should* use the 'I' prefix?
"interface-name": [true, "never-prefix"],
Copy link
Collaborator Author

@seanf seanf Jan 14, 2018

Choose a reason for hiding this comment

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

@BANG88 I wasn't sure if idiomatic TypeScript required "I" interfaces, but the guidelines for TypeScript itself advise against them, so I'm inclined to disallow the I prefix (and remove this TODO comment). Any objection?

Copy link
Owner

Choose a reason for hiding this comment

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

No. this just some coding style not strict rule. for the simple package we do not want too much configurations.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@BANG88 Well, tslint is going to be strict about this rule. I think I could disable the rule entirely, but I think it's important to be consistent, one way or another. Having some interfaces with I and some without is confusing.

@baktun14
Copy link
Contributor

@seanf Hey great refactor! <3

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.

3 participants