Merge pull request #17744 from atom/fix-17535

Teach Pane to always look for a pane item's onDidTerminatePendingState function
This commit is contained in:
Jason Rudolph
2018-07-26 08:44:49 -04:00
committed by GitHub
2 changed files with 35 additions and 7 deletions

View File

@@ -219,6 +219,34 @@ describe('Pane', () => {
runs(() => expect(eventOrder).toEqual(['add', 'remove']))
})
it('subscribes to be notified when item terminates its pending state', () => {
const fakeDisposable = { dispose: () => {} }
const spy = jasmine.createSpy('onDidTerminatePendingState').andReturn((fakeDisposable))
const pane = new Pane(paneParams({items: []}))
const item = {
getTitle: () => '',
onDidTerminatePendingState: spy
}
pane.addItem(item)
expect(spy).toHaveBeenCalled()
})
it('subscribes to be notified when item is destroyed', () => {
const fakeDisposable = { dispose: () => {} }
const spy = jasmine.createSpy('onDidDestroy').andReturn((fakeDisposable))
const pane = new Pane(paneParams({items: []}))
const item = {
getTitle: () => '',
onDidDestroy: spy
}
pane.addItem(item)
expect(spy).toHaveBeenCalled()
})
describe('when using the old API of ::addItem(item, index)', () => {
beforeEach(() => spyOn(Grim, 'deprecate'))

View File

@@ -614,15 +614,15 @@ class Pane {
if (this.items.includes(item)) return
const itemSubscriptions = new CompositeDisposable()
this.subscriptionsPerItem.set(item, itemSubscriptions)
if (typeof item.onDidDestroy === 'function') {
const itemSubscriptions = new CompositeDisposable()
itemSubscriptions.add(item.onDidDestroy(() => this.removeItem(item, false)))
if (typeof item.onDidTerminatePendingState === 'function') {
itemSubscriptions.add(item.onDidTerminatePendingState(() => {
if (this.getPendingItem() === item) this.clearPendingItem()
}))
}
this.subscriptionsPerItem.set(item, itemSubscriptions)
}
if (typeof item.onDidTerminatePendingState === 'function') {
itemSubscriptions.add(item.onDidTerminatePendingState(() => {
if (this.getPendingItem() === item) this.clearPendingItem()
}))
}
this.items.splice(index, 0, item)