Skip to content

Commit

Permalink
Add test-case to see when components are unmounted
Browse files Browse the repository at this point in the history
Does currently work correctly, more info is needed in the ticket

re #18
  • Loading branch information
ThaNarie committed Nov 15, 2021
1 parent f549e9e commit e46b0a7
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/src/components/core/lifecycle/OnUnmounted.stories.ts
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>`,
});

0 comments on commit e46b0a7

Please sign in to comment.