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

v2.1 Implementation of Subscription component #1483

Conversation

excitement-engineer
Copy link
Contributor

@excitement-engineer excitement-engineer commented Dec 28, 2017

Implementation of the Subscription component for the next version of react-apollo.

@rosskevin
Copy link
Contributor

rosskevin commented Dec 28, 2017

Noun or verb?

<Subscription subscription={subscription}>

or

<Subscribe subscription={subscription}>

I'm using Query now and I don't like the repetitiveness of the DocumentNode prop of the same name as the component. Same here with subscription. I wonder if we should choose something simpler/less verbose.

I have no idea what is generic, but this illustrates where I'm going:

<Subscribe node={subscripton}>
<Query node={query}>

@excitement-engineer
Copy link
Contributor Author

I'm in favour of sticking to the exact language used by graphql for the component: Query, Mutation and Subscription to prevent any confusion, what do you think?

A node does not intuitively signal a DocumentNode to me, should we simply call the prop query?

<Query query={...} />
<Subscription query={...} />

@rosskevin
Copy link
Contributor

I'm not sure. Using query is a length improvement, and I think an accurate name (not positive though). Either way I want to reduce length without reducing explicitness or clarity.

@excitement-engineer excitement-engineer changed the title [WIP] Implementation of Subscription component v2.1 Implementation of Subscription component Dec 30, 2017
@apollo-cla
Copy link

apollo-cla commented Dec 30, 2017

Warnings
⚠️

❗ Big PR

⚠️

There are library changes, but not tests. That's OK as long as you're refactoring existing code

Generated by 🚫 dangerJS

Copy link
Contributor

@rosskevin rosskevin left a comment

Choose a reason for hiding this comment

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

Only one change on type. The rest is really just style preferences which are more or less personal choices - no real reason I'm the authority that says it must be different 😄

children: (result: any) => React.ReactNode;
}

export interface SubscriptionState<TData = any> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove export. I just call these State since they are essentially private/not exported.

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 tried this but typescript doesn't allow it with error:

'extends' clause of exported class 'Subscription' has or is using private name 'SubscriptionState'.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, if TS is going to complain and require the export (an obscure open issue in TS), then it is best to leave it as-is.


private client: ApolloClient<any>;
//TODO: What is the type here?
private queryObservable: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

From ApolloClient.d.ts (your IDE should allow you to follow the declaration of client.subscribe

import {Observable} from 'apollo-client/util/Observable'
Observable<any>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great thanks!

this.initialize(nextProps);
this.startSubscription();
this.setState(this.getInitialState(nextProps));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

My preference in this section is that it is unnecessarily broken up. initialize and getInitialState are not reused, so i would simply bring their implementation up here. It increases comprehension without increasing complexity.

I could even say the same about start/end subscription - but I would have to see it before making a judgement.

My go-to in this case would probably be all that code right here. All init code, not reused, fairly simple, and if needed, a one-line comment to break it up.

Reasoning: when I see code in a method that is one-line I think - this must be reused, where is it reused and why?

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'm not sure I understand? All of these methods are being reused in the component

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, ok good. It would have been easier for me to spot in my IDE, but you are right, these are needed.

@excitement-engineer excitement-engineer merged commit 2341454 into apollographql:master Dec 30, 2017
@excitement-engineer excitement-engineer deleted the subscription-component branch December 30, 2017 15:35
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.

3 participants