-
Notifications
You must be signed in to change notification settings - Fork 668
Introduce autoDestroy config option #1240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ export default { | |
mocks: {}, | ||
methods: {}, | ||
provide: {}, | ||
silent: true | ||
silent: true, | ||
autoDestroy: false | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,13 @@ import { matches } from './matches' | |
import createDOMEvent from './create-dom-event' | ||
import { throwIfInstancesThrew } from './error' | ||
|
||
const wrapperInstances = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be an array because when passing a hook function it can happen that multiple wrapper instances were created. |
||
|
||
const destroyAllInstances = () => { | ||
wrapperInstances.forEach(wrapper => wrapper.destroy()) | ||
wrapperInstances.length = 0 | ||
} | ||
|
||
export default class Wrapper implements BaseWrapper { | ||
+vnode: VNode | null | ||
+vm: Component | void | ||
|
@@ -67,6 +74,17 @@ export default class Wrapper implements BaseWrapper { | |
) { | ||
this.isFunctionalComponent = true | ||
} | ||
|
||
const { autoDestroy } = config | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to allow overriding this via wrapper options? |
||
if (autoDestroy) { | ||
if (autoDestroy instanceof Function) { | ||
autoDestroy(destroyAllInstances) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is wrong. It will for example result in |
||
} else { | ||
destroyAllInstances() | ||
} | ||
|
||
wrapperInstances.push(this) | ||
} | ||
} | ||
|
||
at(): void { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false
should be the default because that is the current behavior