Skip to content

Commit

Permalink
fix(core): fix add effects memo leak in form umount (#2050)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang authored Aug 26, 2021
1 parent 0cc9067 commit f753ba1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/core/src/__tests__/heart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,15 @@ test('add/remove lifecycle', () => {
heart.publish('event')
expect(handler).toBeCalledTimes(1)
})

test('add/clear lifecycle', () => {
const handler = jest.fn()
const heart = new Heart()
heart.addLifeCycles('xxx', [new LifeCycle('event', handler)])
heart.addLifeCycles('yyy')
heart.publish('event')
expect(handler).toBeCalledTimes(1)
heart.clear()
heart.publish('event')
expect(handler).toBeCalledTimes(1)
})
1 change: 1 addition & 0 deletions packages/core/src/models/Heart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class Heart<Payload = any, Context = any> extends Subscribable {

clear = () => {
this.lifecycles = []
this.outerLifecycles.clear()
this.unsubscribe()
}
}

0 comments on commit f753ba1

Please sign in to comment.