-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test-case to see when components are unmounted
Does currently work correctly, more info is needed in the ticket re #18
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
examples/src/components/core/lifecycle/OnUnmounted.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { html } from '@muban/template'; | ||
import type { Story } from '@muban/storybook/dist/client/preview/types-6-0'; | ||
import { ref } from '@vue/reactivity'; | ||
import { computed } from '@vue/runtime-core'; | ||
import { bind, defineComponent, onMounted, onUnmounted } from '../../../../../src'; | ||
|
||
export default { | ||
title: 'core/lifecycle/onUnmounted', | ||
}; | ||
|
||
const Child = defineComponent({ | ||
name: 'child', | ||
setup() { | ||
console.log('setup'); | ||
onMounted(() => { | ||
console.log('+ child mounted'); | ||
}); | ||
onUnmounted(() => { | ||
console.log('- child unmounted'); | ||
}); | ||
return []; | ||
}, | ||
}); | ||
|
||
/** | ||
* Tries to test if a child component stays mounted when parent is set to display:none | ||
*/ | ||
export const Default: Story = () => ({ | ||
component: defineComponent({ | ||
name: 'onUnmounted', | ||
components: [Child], | ||
refs: { | ||
content: 'content', | ||
toggle: 'toggle', | ||
}, | ||
setup({ refs }) { | ||
const isVisible = ref<boolean>(true); | ||
|
||
return [ | ||
bind(refs.toggle, { | ||
checked: isVisible, | ||
}), | ||
bind(refs.content, { | ||
style: { display: computed(() => (isVisible.value ? 'block' : 'none')) }, | ||
}), | ||
]; | ||
}, | ||
}), | ||
template: () => html` <div data-component="onUnmounted"> | ||
<div><input data-ref="toggle" type="checkbox" />toggle</div> | ||
<div data-ref="content"> | ||
<div data-component="child">Child content</div> | ||
</div> | ||
</div>`, | ||
}); |