Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit be9284c

Browse files
committed
Replace remoteOperationObserver with a Refresher
1 parent ac0db9c commit be9284c

16 files changed

+41
-163
lines changed

lib/containers/current-pull-request-container.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {QueryRenderer, graphql} from 'react-relay';
44
import {Disposable} from 'event-kit';
55

66
import {autobind, CHECK_SUITE_PAGE_SIZE, CHECK_RUN_PAGE_SIZE} from '../helpers';
7-
import {
8-
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
9-
} from '../prop-types';
7+
import {RemotePropType, RemoteSetPropType, BranchSetPropType, EndpointPropType} from '../prop-types';
108
import IssueishListController, {BareIssueishListController} from '../controllers/issueish-list-controller';
119
import CreatePullRequestTile from '../views/create-pull-request-tile';
1210
import RelayNetworkLayerManager from '../relay-network-layer-manager';
@@ -30,7 +28,6 @@ export default class CurrentPullRequestContainer extends React.Component {
3028
limit: PropTypes.number,
3129

3230
// Repository model attributes
33-
remoteOperationObserver: OperationStateObserverPropType.isRequired,
3431
remote: RemotePropType.isRequired,
3532
remotes: RemoteSetPropType.isRequired,
3633
branches: BranchSetPropType.isRequired,
@@ -120,18 +117,10 @@ export default class CurrentPullRequestContainer extends React.Component {
120117
}
121118

122119
renderEmptyResult() {
123-
this.sub.dispose();
124-
this.sub = this.props.remoteOperationObserver.onDidComplete(() => this.forceUpdate());
125-
126120
return <BareIssueishListController isLoading={false} {...this.controllerProps()} />;
127121
}
128122

129-
renderQueryResult({error, props, retry}) {
130-
if (retry) {
131-
this.sub.dispose();
132-
this.sub = this.props.remoteOperationObserver.onDidComplete(retry);
133-
}
134-
123+
renderQueryResult({error, props}) {
135124
if (error) {
136125
return (
137126
<BareIssueishListController

lib/containers/github-tab-container.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import yubikiri from 'yubikiri';
4-
import {CompositeDisposable, Disposable} from 'event-kit';
4+
import {Disposable} from 'event-kit';
55

66
import {GithubLoginModelPropType, RefHolderPropType} from '../prop-types';
77
import OperationStateObserver, {PUSH, PULL, FETCH} from '../models/operation-state-observer';
@@ -91,7 +91,6 @@ export default class GitHubTabContainer extends React.Component {
9191
<GitHubTabController
9292
{...this.props}
9393
refresher={this.state.refresher}
94-
remoteOperationObserver={this.state.remoteOperationObserver}
9594

9695
allRemotes={new RemoteSet()}
9796
branches={new BranchSet()}
@@ -107,7 +106,6 @@ export default class GitHubTabContainer extends React.Component {
107106
<GitHubTabController
108107
{...this.props}
109108
refresher={this.state.refresher}
110-
remoteOperationObserver={this.state.remoteOperationObserver}
111109

112110
allRemotes={new RemoteSet()}
113111
branches={new BranchSet()}
@@ -123,7 +121,6 @@ export default class GitHubTabContainer extends React.Component {
123121
{...data}
124122
{...this.props}
125123
refresher={this.state.refresher}
126-
remoteOperationObserver={this.state.remoteOperationObserver}
127124
isLoading={false}
128125
/>
129126
);

lib/containers/issueish-search-container.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {QueryRenderer, graphql} from 'react-relay';
44
import {Disposable} from 'event-kit';
55

66
import {autobind, CHECK_SUITE_PAGE_SIZE, CHECK_RUN_PAGE_SIZE} from '../helpers';
7-
import {SearchPropType, OperationStateObserverPropType, EndpointPropType} from '../prop-types';
7+
import {SearchPropType, EndpointPropType} from '../prop-types';
88
import IssueishListController, {BareIssueishListController} from '../controllers/issueish-list-controller';
99
import RelayNetworkLayerManager from '../relay-network-layer-manager';
1010

@@ -17,7 +17,6 @@ export default class IssueishSearchContainer extends React.Component {
1717
// Search model
1818
limit: PropTypes.number,
1919
search: SearchPropType.isRequired,
20-
remoteOperationObserver: OperationStateObserverPropType.isRequired,
2120

2221
// Action methods
2322
onOpenIssueish: PropTypes.func.isRequired,
@@ -89,12 +88,7 @@ export default class IssueishSearchContainer extends React.Component {
8988
);
9089
}
9190

92-
renderQueryResult({error, props, retry}) {
93-
if (retry) {
94-
this.sub.dispose();
95-
this.sub = this.props.remoteOperationObserver.onDidComplete(retry);
96-
}
97-
91+
renderQueryResult({error, props}) {
9892
if (error) {
9993
return (
10094
<BareIssueishListController

lib/containers/remote-container.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import PropTypes from 'prop-types';
33
import {QueryRenderer, graphql} from 'react-relay';
44

55
import {incrementCounter} from '../reporter-proxy';
6-
import {
7-
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
8-
} from '../prop-types';
6+
import {RemotePropType, RemoteSetPropType, BranchSetPropType, RefresherPropType, EndpointPropType} from '../prop-types';
97
import RelayNetworkLayerManager from '../relay-network-layer-manager';
108
import {UNAUTHENTICATED, INSUFFICIENT} from '../shared/keytar-strategy';
119
import RemoteController from '../controllers/remote-controller';
@@ -21,7 +19,7 @@ export default class RemoteContainer extends React.Component {
2119
endpoint: EndpointPropType.isRequired,
2220

2321
// Repository attributes
24-
remoteOperationObserver: OperationStateObserverPropType.isRequired,
22+
refresher: RefresherPropType.isRequired,
2523
pushInProgress: PropTypes.bool.isRequired,
2624
workingDirectory: PropTypes.string,
2725
workspace: PropTypes.object.isRequired,
@@ -104,6 +102,8 @@ export default class RemoteContainer extends React.Component {
104102
}
105103

106104
renderWithResult({error, props, retry}, token) {
105+
this.props.refresher.setRetryCallback(this, retry);
106+
107107
if (error) {
108108
return (
109109
<QueryErrorView
@@ -126,7 +126,6 @@ export default class RemoteContainer extends React.Component {
126126

127127
repository={props.repository}
128128

129-
remoteOperationObserver={this.props.remoteOperationObserver}
130129
workingDirectory={this.props.workingDirectory}
131130
workspace={this.props.workspace}
132131
remote={this.props.remote}

lib/controllers/github-tab-controller.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33

44
import {
5-
GithubLoginModelPropType, RefHolderPropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType,
5+
GithubLoginModelPropType, RefHolderPropType, RemoteSetPropType, BranchSetPropType, RefresherPropType,
66
} from '../prop-types';
77
import GitHubTabView from '../views/github-tab-view';
88

99
export default class GitHubTabController extends React.Component {
1010
static propTypes = {
1111
workspace: PropTypes.object.isRequired,
12-
remoteOperationObserver: OperationStateObserverPropType.isRequired,
12+
refresher: RefresherPropType.isRequired,
1313
loginModel: GithubLoginModelPropType.isRequired,
1414
rootHolder: RefHolderPropType.isRequired,
1515

@@ -47,7 +47,7 @@ export default class GitHubTabController extends React.Component {
4747
return (
4848
<GitHubTabView
4949
workspace={this.props.workspace}
50-
remoteOperationObserver={this.props.remoteOperationObserver}
50+
refresher={this.props.refresher}
5151
loginModel={this.props.loginModel}
5252
rootHolder={this.props.rootHolder}
5353

lib/controllers/issueish-searches-controller.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import React from 'react';
22
import PropTypes from 'prop-types';
33
import {shell} from 'electron';
44

5-
import {
6-
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
7-
} from '../prop-types';
5+
import {RemotePropType, RemoteSetPropType, BranchSetPropType, EndpointPropType} from '../prop-types';
86
import Search from '../models/search';
97
import IssueishSearchContainer from '../containers/issueish-search-container';
108
import CurrentPullRequestContainer from '../containers/current-pull-request-container';
@@ -31,7 +29,6 @@ export default class IssueishSearchesController extends React.Component {
3129
workspace: PropTypes.object.isRequired,
3230

3331
// Repository model attributes
34-
remoteOperationObserver: OperationStateObserverPropType.isRequired,
3532
workingDirectory: PropTypes.string,
3633
remote: RemotePropType.isRequired,
3734
remotes: RemoteSetPropType.isRequired,
@@ -60,7 +57,6 @@ export default class IssueishSearchesController extends React.Component {
6057
repository={this.props.repository}
6158
token={this.props.token}
6259
endpoint={this.props.endpoint}
63-
remoteOperationObserver={this.props.remoteOperationObserver}
6460
remote={this.props.remote}
6561
remotes={this.props.remotes}
6662
branches={this.props.branches}
@@ -79,7 +75,6 @@ export default class IssueishSearchesController extends React.Component {
7975
token={this.props.token}
8076
endpoint={this.props.endpoint}
8177
search={search}
82-
remoteOperationObserver={this.props.remoteOperationObserver}
8378

8479
onOpenIssueish={this.onOpenIssueish}
8580
onOpenSearch={this.onOpenSearch}

lib/controllers/remote-controller.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import {shell} from 'electron';
44

55
import {autobind} from '../helpers';
66
import {incrementCounter} from '../reporter-proxy';
7-
import {
8-
RemotePropType, RemoteSetPropType, BranchSetPropType, OperationStateObserverPropType, EndpointPropType,
9-
} from '../prop-types';
7+
import {RemotePropType, RemoteSetPropType, BranchSetPropType, EndpointPropType} from '../prop-types';
108
import IssueishSearchesController from './issueish-searches-controller';
119

1210
export default class RemoteController extends React.Component {
@@ -25,7 +23,6 @@ export default class RemoteController extends React.Component {
2523
token: PropTypes.string.isRequired,
2624

2725
// Repository derived attributes
28-
remoteOperationObserver: OperationStateObserverPropType.isRequired,
2926
workingDirectory: PropTypes.string,
3027
workspace: PropTypes.object.isRequired,
3128
remote: RemotePropType.isRequired,
@@ -49,7 +46,6 @@ export default class RemoteController extends React.Component {
4946
endpoint={this.props.endpoint}
5047
token={this.props.token}
5148

52-
remoteOperationObserver={this.props.remoteOperationObserver}
5349
workingDirectory={this.props.workingDirectory}
5450
repository={this.props.repository}
5551

lib/prop-types.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ export const OperationStateObserverPropType = PropTypes.shape({
120120
dispose: PropTypes.func.isRequired,
121121
});
122122

123+
export const RefresherPropType = PropTypes.shape({
124+
setRetryCallback: PropTypes.func.isRequired,
125+
trigger: PropTypes.func.isRequired,
126+
deregister: PropTypes.func.isRequired,
127+
});
128+
123129
export const IssueishPropType = PropTypes.shape({
124130
getNumber: PropTypes.func.isRequired,
125131
getTitle: PropTypes.func.isRequired,

lib/views/github-tab-view.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33

44
import {
55
GithubLoginModelPropType, RefHolderPropType, RemoteSetPropType, RemotePropType, BranchSetPropType, BranchPropType,
6-
OperationStateObserverPropType,
6+
RefresherPropType,
77
} from '../prop-types';
88
import LoadingView from './loading-view';
99
import RemoteSelectorView from './remote-selector-view';
@@ -16,7 +16,7 @@ import RemoteContainer from '../containers/remote-container';
1616
export default class GitHubTabView extends React.Component {
1717
static propTypes = {
1818
workspace: PropTypes.object.isRequired,
19-
remoteOperationObserver: OperationStateObserverPropType.isRequired,
19+
refresher: RefresherPropType.isRequired,
2020
loginModel: GithubLoginModelPropType.isRequired,
2121
rootHolder: RefHolderPropType.isRequired,
2222

@@ -83,7 +83,7 @@ export default class GitHubTabView extends React.Component {
8383
loginModel={this.props.loginModel}
8484
endpoint={this.props.currentRemote.getEndpoint()}
8585

86-
remoteOperationObserver={this.props.remoteOperationObserver}
86+
refresher={this.props.refresher}
8787
pushInProgress={this.props.pushInProgress}
8888
workingDirectory={this.props.workingDirectory}
8989
workspace={this.props.workspace}

test/containers/current-pull-request-container.test.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {shallow} from 'enzyme';
33
import {QueryRenderer} from 'react-relay';
44

55
import CurrentPullRequestContainer from '../../lib/containers/current-pull-request-container';
6-
import {ManualStateObserver} from '../helpers';
76
import {queryBuilder} from '../builder/graphql/query';
87
import Remote from '../../lib/models/remote';
98
import RemoteSet from '../../lib/models/remote-set';
@@ -15,12 +14,6 @@ import repositoryQuery from '../../lib/containers/__generated__/remoteContainerQ
1514
import currentQuery from '../../lib/containers/__generated__/currentPullRequestContainerQuery.graphql.js';
1615

1716
describe('CurrentPullRequestContainer', function() {
18-
let observer;
19-
20-
beforeEach(function() {
21-
observer = new ManualStateObserver();
22-
});
23-
2417
function buildApp(overrideProps = {}) {
2518
const origin = new Remote('origin', '[email protected]:atom/github.git');
2619
const upstreamBranch = Branch.createRemoteTracking('refs/remotes/origin/master', 'origin', 'refs/heads/master');
@@ -37,7 +30,6 @@ describe('CurrentPullRequestContainer', function() {
3730

3831
token="1234"
3932
endpoint={origin.getEndpoint()}
40-
remoteOperationObserver={observer}
4133
remote={origin}
4234
remotes={remotes}
4335
branches={branches}
@@ -209,15 +201,4 @@ describe('CurrentPullRequestContainer', function() {
209201
assert.isTrue(filterFn({getHeadRepositoryID: () => '100'}));
210202
assert.isFalse(filterFn({getHeadRepositoryID: () => '12'}));
211203
});
212-
213-
it('performs the query again when a remote operation completes', function() {
214-
const wrapper = shallow(buildApp());
215-
216-
const props = queryBuilder(currentQuery).build();
217-
const retry = sinon.spy();
218-
wrapper.find(QueryRenderer).renderProp('render')({error: null, props, retry});
219-
220-
observer.trigger();
221-
assert.isTrue(retry.called);
222-
});
223204
});

0 commit comments

Comments
 (0)