mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 10:21:05 +00:00
Refactor onDestroy
to use onMount
return function (#914)
* refactor(select-item): replace onDestroy with onMount return function * refactor(date-picker): replace onDestroy with onMount return function * refactor(switch): replace onDestroy with onMount return function * refactor(composed-modal): replace onDestroy with onMount return function
This commit is contained in:
parent
a160ef3b40
commit
dfd53ce09b
4 changed files with 23 additions and 21 deletions
|
@ -36,7 +36,6 @@
|
||||||
setContext,
|
setContext,
|
||||||
onMount,
|
onMount,
|
||||||
afterUpdate,
|
afterUpdate,
|
||||||
onDestroy,
|
|
||||||
} from "svelte";
|
} from "svelte";
|
||||||
import { writable } from "svelte/store";
|
import { writable } from "svelte/store";
|
||||||
|
|
||||||
|
@ -73,13 +72,14 @@
|
||||||
let opened = false;
|
let opened = false;
|
||||||
$: didOpen = open;
|
$: didOpen = open;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(() => {
|
||||||
await tick();
|
tick().then(() => {
|
||||||
focus();
|
focus();
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
return () => {
|
||||||
document.body.classList.remove("bx--body--with-modal-open");
|
document.body.classList.remove("bx--body--with-modal-open");
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
/** Obtain a reference to the button HTML element */
|
/** Obtain a reference to the button HTML element */
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
import { afterUpdate, getContext, onDestroy } from "svelte";
|
import { afterUpdate, getContext, onMount } from "svelte";
|
||||||
|
|
||||||
const ctx = getContext("ContentSwitcher");
|
const ctx = getContext("ContentSwitcher");
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onMount(() => {
|
||||||
unsubscribe();
|
return () => unsubscribe();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -70,7 +70,7 @@
|
||||||
createEventDispatcher,
|
createEventDispatcher,
|
||||||
setContext,
|
setContext,
|
||||||
afterUpdate,
|
afterUpdate,
|
||||||
onDestroy,
|
onMount,
|
||||||
} from "svelte";
|
} from "svelte";
|
||||||
import { writable, derived } from "svelte/store";
|
import { writable, derived } from "svelte/store";
|
||||||
import { createCalendar } from "./createCalendar";
|
import { createCalendar } from "./createCalendar";
|
||||||
|
@ -175,6 +175,15 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
return () => {
|
||||||
|
if (calendar) {
|
||||||
|
calendar.destroy();
|
||||||
|
calendar = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
afterUpdate(() => {
|
afterUpdate(() => {
|
||||||
if (calendar) {
|
if (calendar) {
|
||||||
if ($range) {
|
if ($range) {
|
||||||
|
@ -188,13 +197,6 @@
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
|
||||||
if (calendar) {
|
|
||||||
calendar.destroy();
|
|
||||||
calendar = null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$: inputValue.set(value);
|
$: inputValue.set(value);
|
||||||
$: value = $inputValue;
|
$: value = $inputValue;
|
||||||
$: inputValueFrom.set(valueFrom);
|
$: inputValueFrom.set(valueFrom);
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
/** Set to `true` to disable the option */
|
/** Set to `true` to disable the option */
|
||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
|
|
||||||
import { getContext, onDestroy } from "svelte";
|
import { getContext, onMount } from "svelte";
|
||||||
|
|
||||||
const ctx = getContext("Select") || getContext("TimePickerSelect");
|
const ctx = getContext("Select") || getContext("TimePickerSelect");
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@
|
||||||
selected = currentValue === value;
|
selected = currentValue === value;
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onMount(() => {
|
||||||
unsubscribe();
|
return () => unsubscribe();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue