Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3b2712

Browse files
committed
Increasingly messy hack for FilePatchController's refs
1 parent 1a5401d commit b3b2712

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

lib/controllers/root-controller.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export default class RootController extends React.Component {
9696
this.refGitTabController = new RefHolder();
9797
this.refGitTabWrapperController = new RefHolder();
9898
this.refGitHubTabController = new RefHolder();
99+
this.filePatchRefs = new Map();
99100

100101
this.gitTabTracker = new TabTracker('git', {
101102
uri: 'atom-github://dock-item/git',
@@ -309,13 +310,21 @@ export default class RootController extends React.Component {
309310
return this.props.filePatchItems.map(item => {
310311
const {filePath, stagingStatus, workdir} = getPropsFromUri(item.uri);
311312

313+
let refHolder = this.filePatchRefs.get(item.uri);
314+
if (!refHolder) {
315+
refHolder = new RefHolder();
316+
this.filePatchRefs.set(refHolder);
317+
}
318+
312319
return (
313320
<PaneItem
314321
key={item.key}
315322
workspace={this.props.workspace}
316323
onDidCloseItem={this.removeFilePatchItem}
317-
stubItem={item}>
324+
stubItem={item}
325+
itemHolder={refHolder}>
318326
<FilePatchController
327+
ref={refHolder.setter}
319328
deserializers={this.props.deserializers}
320329
commandRegistry={this.props.commandRegistry}
321330
tooltips={this.props.tooltips}
@@ -366,6 +375,14 @@ export default class RootController extends React.Component {
366375
this.props.repository.onMergeError(() => this.gitTabTracker.ensureVisible()),
367376
this.refGitTabWrapperController.observe(c => this.refGitTabController.setter(c.getWrappedComponentInstance())),
368377
);
378+
379+
const existingURIs = new Set(this.props.filePatchItems.map(item => item.uri));
380+
const retainedURIs = [...this.filePatchRefs.keys()];
381+
for (const uri of retainedURIs) {
382+
if (!existingURIs.has(uri)) {
383+
this.filePatchRefs.delete(uri);
384+
}
385+
}
369386
}
370387

371388
onConsumeStatusBar(statusBar) {

0 commit comments

Comments
 (0)