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

Type Transaction #7581

Merged
merged 1 commit into from
Aug 28, 2016
Merged

Type Transaction #7581

merged 1 commit into from
Aug 28, 2016

Conversation

vjeux
Copy link
Contributor

@vjeux vjeux commented Aug 26, 2016

This one is interesting because we have transaction objects being passed around everywhere in the codebase but there's actually no Transaction class. It's a "mixin" that comes to life by being Object.assigned to the prototype of a real "class" (before class was cool!). Therefore, we can't just say var Transaction = require('Transaction'); (transaction: Transaction) => { } because it would be the object that contains a mixin and not an instance of a transaction.

The trick I use is to export TransactionType and alias it to Transaction in the file as it doesn't actually require transaction. In case they do, we'll figure it out, but in the few files I looked at, it doesn't seem to be the case.

For the perform function, it actually typechecks pretty well!

screen shot 2016-08-26 at 3 22 06 pm

@vjeux
Copy link
Contributor Author

vjeux commented Aug 26, 2016

cc @avikchaudhuri, @sebmarkbage

@@ -39,7 +39,7 @@ function warnNoop(publicInstance: ReactComponent<any, any, any>, callerName: str
* @param {Transaction} transaction
*/
class ReactServerUpdateQueue {
/* :: transaction: Transaction; */
transaction: Transaction;

constructor(transaction: Transaction) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

since Transaction was not flowified, this didn't do anything!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The flow team wants to make this an error in the future. We shouldn't be able to use a non-flow file as type as it silently turns it into any. (Internal discussion: https://www.facebook.com/groups/flowtype/permalink/1132421916806422/ )

@vjeux vjeux force-pushed the type_Transaction branch 2 times, most recently from b575dfb to 72db636 Compare August 27, 2016 02:56
@vjeux
Copy link
Contributor Author

vjeux commented Aug 27, 2016

Ok, updated with a different proposal: it turns out that no one uses the second export (OBSERVED_ERROR ). So, instead of exporting an object with a "Mixin" (which is confusing as hell to me), I return the Transaction object and a type named Transaction.

So, now for the call site it is super simple, if you want the implementation you do

var Transaction = require('Transaction');

if you want the type you do

import type { Transaction } from 'Transaction';

It's a little bit weird inside of the file as I need to name Transaction something else because the export would overshadow the name. I chose TransactionImpl which isn't soo bad.

What do you think @sebmarkbage?

This one is interesting because we have transaction objects being passed around everywhere in the codebase but there's actually no Transaction class. It's a "mixin" that comes to life by being Object.assigned to the prototype of a real "class" (before class was cool!). Therefore, we can't just say `var Transaction = require('Transaction'); (transaction: Transaction) => { }` because it would be the object that contains a mixin and not an instance of a transaction.

The trick I use is to export `TransactionType` and alias it to `Transaction` in the file as it doesn't actually require transaction. In case they do, we'll figure it out, but in the few files I looked at, it doesn't seem to be the case.

For the perform function, it actually typechecks pretty well!
@sebmarkbage
Copy link
Collaborator

The problem is that now it is inconsistent with all the other Mixin exports we have which do have multiple exports. I've been trying to get rid of most of them though.

@vjeux
Copy link
Contributor Author

vjeux commented Aug 28, 2016

By searching for .Mixin I found three kinds:

  • Transaction (this one)
  • ReactMultiChild: only returns a mixin
  • ReactCompositeComponent: only returns a mixin
  • ReactDOMComponent: it returns a function that is mixed with the mixin it exports. The mixin it exports is only used for its own test, so it's not a big deal to leave it as is.
  • ReactNativeBaseComponent: the mixin is only used inside of the file to setup the function it exports.
  • ReactStateSetters: this is a real React mixin and not an internal one

Here's my suggestion: we update the three that only return a mixin to just return the mixin and don't touch the other ones. I don't think that it's going to leave the codebase in an inconsistent way.

vjeux added a commit to vjeux/react that referenced this pull request Aug 28, 2016
As mentioned in facebook#7581 (comment) we can remove the Mixin layer of indirection as it only exports a Mixin and I find it confusing.
vjeux added a commit to vjeux/react that referenced this pull request Aug 28, 2016
As mentioned in facebook#7581 (comment) we can remove the Mixin layer of indirection as it only exports a Mixin and I find it confusing.
@vjeux
Copy link
Contributor Author

vjeux commented Aug 28, 2016

I went ahead and created a PR for

If you think it's a good idea I can merge them all. If not, please let me know how you want me to proceed forward :)

@sebmarkbage
Copy link
Collaborator

Sounds good.

vjeux added a commit that referenced this pull request Aug 28, 2016
As mentioned in #7581 (comment) we can remove the Mixin layer of indirection as it only exports a Mixin and I find it confusing.
vjeux added a commit that referenced this pull request Aug 28, 2016
As mentioned in #7581 (comment) we can remove the Mixin layer of indirection as it only exports a Mixin and I find it confusing.
@vjeux vjeux added this to the 15-next milestone Aug 28, 2016
@vjeux vjeux merged commit a3e576e into facebook:master Aug 28, 2016
@zpao zpao modified the milestones: 15-next, 15.4.0 Oct 4, 2016
@zpao zpao modified the milestones: 15.4.0, 15-next Oct 4, 2016
zpao pushed a commit that referenced this pull request Oct 4, 2016
As mentioned in #7581 (comment) we can remove the Mixin layer of indirection as it only exports a Mixin and I find it confusing.
(cherry picked from commit dd0c65c)
zpao pushed a commit that referenced this pull request Oct 4, 2016
This one is interesting because we have transaction objects being passed around everywhere in the codebase but there's actually no Transaction class. It's a "mixin" that comes to life by being Object.assigned to the prototype of a real "class" (before class was cool!). Therefore, we can't just say `var Transaction = require('Transaction'); (transaction: Transaction) => { }` because it would be the object that contains a mixin and not an instance of a transaction.

The trick I use is to export `TransactionType` and alias it to `Transaction` in the file as it doesn't actually require transaction. In case they do, we'll figure it out, but in the few files I looked at, it doesn't seem to be the case.

For the perform function, it actually typechecks pretty well!
(cherry picked from commit a3e576e)
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.

4 participants