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

Skip to content

Commit c76a00d

Browse files
committed
changed file item
1 parent 01f64ea commit c76a00d

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

lib/items/changed-file-item.js

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
3-
import {Emitter} from 'event-kit';
3+
import ItemComponent from './item-component';
44

55
import {WorkdirContextPoolPropType} from '../prop-types';
6-
import {autobind} from '../helpers';
76
import ChangedFileContainer from '../containers/changed-file-container';
8-
import RefHolder from '../models/ref-holder';
97

10-
export default class ChangedFileItem extends React.Component {
8+
export default class ChangedFileItem extends ItemComponent {
119
static propTypes = {
1210
workdirContextPool: WorkdirContextPoolPropType.isRequired,
1311

@@ -36,15 +34,9 @@ export default class ChangedFileItem extends React.Component {
3634
}
3735

3836
constructor(props) {
39-
super(props);
40-
autobind(this, 'destroy');
37+
super(props, {});
4138

42-
this.emitter = new Emitter();
43-
this.isDestroyed = false;
44-
this.hasTerminatedPendingState = false;
45-
46-
this.refEditor = new RefHolder();
47-
this.refEditor.observe(editor => {
39+
this.refHolder.observe(editor => {
4840
this.emitter.emit('did-change-embedded-text-editor', editor);
4941
});
5042
}
@@ -67,18 +59,6 @@ export default class ChangedFileItem extends React.Component {
6759
return this.emitter.on('did-terminate-pending-state', callback);
6860
}
6961

70-
destroy() {
71-
/* istanbul ignore else */
72-
if (!this.isDestroyed) {
73-
this.emitter.emit('did-destroy');
74-
this.isDestroyed = true;
75-
}
76-
}
77-
78-
onDidDestroy(callback) {
79-
return this.emitter.on('did-destroy', callback);
80-
}
81-
8262
render() {
8363
const repository = this.props.workdirContextPool.getContext(this.props.workingDirectory).getRepository();
8464

@@ -87,14 +67,14 @@ export default class ChangedFileItem extends React.Component {
8767
itemType={this.constructor}
8868
repository={repository}
8969
destroy={this.destroy}
90-
refEditor={this.refEditor}
70+
refEditor={this.refHolder}
9171
{...this.props}
9272
/>
9373
);
9474
}
9575

9676
observeEmbeddedTextEditor(cb) {
97-
this.refEditor.map(editor => cb(editor));
77+
this.refHolder.map(editor => cb(editor));
9878
return this.emitter.on('did-change-embedded-text-editor', cb);
9979
}
10080

lib/items/item-component.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React from 'react';
22
import RefHolder from '../models/ref-holder';
33
import {Emitter} from 'event-kit';
4+
import {autobind} from '../helpers';
45

56
export default class ItemComponent extends React.Component {
67

78
constructor(props, {title, icon}) {
89
super(props);
10+
autobind(this, 'destroy');
911

1012
this.title = title;
1113
this.icon = icon;
@@ -24,7 +26,7 @@ export default class ItemComponent extends React.Component {
2426
return this.icon;
2527
}
2628

27-
destroy = () => {
29+
destroy() {
2830
/* istanbul ignore else */
2931
if (!this.isDestroyed) {
3032
this.emitter.emit('did-destroy');

0 commit comments

Comments
 (0)