mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
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:
@@ -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'))
|
||||
|
||||
|
||||
14
src/pane.js
14
src/pane.js
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user