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

Commit 6719293

Browse files
authored
Merge pull request #1016 from atom/ku-next-diff-please
[WIP] Use Atom opener to display file diff
2 parents a09020d + 83e8fb1 commit 6719293

28 files changed

Lines changed: 2159 additions & 2162 deletions

lib/atom-items/stub-item.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,57 @@
11
import {Emitter, CompositeDisposable} from 'event-kit';
22

3+
let key = 0;
34
export default class StubItem {
4-
static stubsBySelector = new Map()
5-
65
// StubItems should only be created by `create` and never constructed directly.
7-
static create(selector, props) {
8-
const stub = new StubItem(selector, props);
6+
static create(name, props, uri = '') {
7+
const stub = new StubItem(name, props, uri);
98
const override = {
109
_getStub: () => stub,
1110
getElement: () => stub.getElement(),
1211
destroy: stub.destroy.bind(stub),
1312
};
1413
const proxy = new Proxy(override, {
15-
get(target, name) {
14+
get(target, propName) {
1615
const item = stub.getRealItem();
17-
if (Reflect.has(target, name)) {
18-
return target[name];
19-
} else if (item && Reflect.has(item, name)) {
20-
let val = item[name];
16+
if (Reflect.has(target, propName)) {
17+
return target[propName];
18+
} else if (item && Reflect.has(item, propName)) {
19+
let val = item[propName];
2120
if (typeof val === 'function') {
2221
val = val.bind(item);
2322
}
2423
return val;
2524
} else {
26-
let val = stub[name];
25+
let val = stub[propName];
2726
if (typeof val === 'function') {
2827
val = val.bind(stub);
2928
}
3029
return val;
3130
}
3231
},
3332
});
34-
this.stubsBySelector.set(selector, proxy);
3533
return proxy;
3634
}
3735

38-
static getBySelector(selector) {
39-
return this.stubsBySelector.get(selector);
40-
}
41-
42-
static getElementBySelector(selector) {
43-
const stub = this.getBySelector(selector);
44-
if (stub) {
45-
return stub.getElement();
46-
} else {
47-
return null;
48-
}
49-
}
50-
51-
constructor(selector, props = {}) {
36+
constructor(name, props = {}, uri) {
5237
this.emitter = new Emitter();
5338
this.subscriptions = new CompositeDisposable();
5439

55-
this.selector = selector;
40+
this.name = name;
5641
this.props = props;
42+
this.uri = uri;
43+
this.key = ++key;
5744
this.element = document.createElement('div');
58-
this.element.classList.add(`github-StubItem-${selector}`);
45+
this.element.classList.add(`github-StubItem-${name}`);
5946
this.realItem = null;
47+
this.realItemPromise = new Promise(res => {
48+
this.resolveRealItemPromise = res;
49+
});
6050
}
6151

6252
setRealItem(item) {
6353
this.realItem = item;
54+
this.resolveRealItemPromise();
6455
this.emitter.emit('did-change-title');
6556
this.emitter.emit('did-change-icon');
6657

@@ -80,10 +71,18 @@ export default class StubItem {
8071
}
8172
}
8273

74+
getRealItemPromise() {
75+
return this.realItemPromise;
76+
}
77+
8378
getRealItem() {
8479
return this.realItem;
8580
}
8681

82+
getURI() {
83+
return this.uri;
84+
}
85+
8786
getTitle() {
8887
return this.props.title || null;
8988
}
@@ -111,9 +110,8 @@ export default class StubItem {
111110
destroy() {
112111
this.subscriptions.dispose();
113112
this.emitter.dispose();
114-
StubItem.stubsBySelector.delete(this.selector);
115-
if (this.actualItem) {
116-
this.actualItem.destroy && this.actualItem.destroy();
113+
if (this.realItem) {
114+
this.realItem.destroy && this.realItem.destroy();
117115
}
118116
}
119117
}

0 commit comments

Comments
 (0)