|
61 | 61 | import { onMount, onDestroy, createEventDispatcher } from 'svelte'; |
62 | 62 | import { debounce as debouncify } from 'lodash-es'; |
63 | 63 | const browser = typeof window === 'object'; |
64 | | - type not = undefined | null; |
65 | 64 |
|
66 | 65 | const nextFrame = browser ? requestAnimationFrame : () => void 0; |
67 | 66 |
|
|
162 | 161 | const dispatch = createEventDispatcher<$$Events>(); |
163 | 162 |
|
164 | 163 | // bind props |
165 | | - export let element: HTMLDivElement | not = undefined; |
166 | | - export let plot: PlotlyHTMLElement | not = undefined; |
| 164 | + export let element: HTMLDivElement | undefined = undefined; |
| 165 | + export let plot: PlotlyHTMLElement | undefined = undefined; |
167 | 166 |
|
168 | 167 | // input props |
169 | 168 | export let libPlotly: typeof import('plotly.js-dist') | null | undefined = undefined; |
|
211 | 210 | previousPlot = plot; |
212 | 211 | } |
213 | 212 |
|
214 | | - const drawUndebounced = ( |
| 213 | + const drawUndebounced = async ( |
215 | 214 | lib: typeof libPlotly, |
216 | | - e: HTMLDivElement | not, |
| 215 | + e: HTMLDivElement | undefined, |
217 | 216 | d: Data[], |
218 | 217 | l: Partial<Layout>, |
219 | 218 | c: Partial<Config> |
220 | 219 | ) => { |
221 | | - if (e) lib?.react(e, d, l, c).then(p => (plot = p)); |
| 220 | + if (lib && e) { |
| 221 | + plot = await lib.react(e, d, l, c); |
| 222 | + } |
222 | 223 | }; |
223 | 224 |
|
224 | 225 | $: draw = debouncify(drawUndebounced, debounceWait, debounceOptions); |
|
230 | 231 | $: fillParent, nextFrame(onResize); |
231 | 232 | $: fillParentWidth = fillParent === true || fillParent === 'width'; |
232 | 233 | $: fillParentHeight = fillParent === true || fillParent === 'height'; |
233 | | - $: parent = element?.parentElement; |
234 | | - let lastParent: typeof parent = null; |
| 234 | + $: parent = element?.parentElement ?? undefined; |
| 235 | + let lastParent: typeof parent = undefined; |
235 | 236 | $: { |
236 | 237 | parentMounted(parent); |
237 | 238 | parentUnmounted(lastParent); |
238 | 239 | lastParent = parent; |
239 | 240 | } |
240 | 241 |
|
241 | | - let resizeObserver: ResizeObserver | not; |
| 242 | + let resizeObserver: ResizeObserver | undefined; |
242 | 243 | onMount(() => (resizeObserver = new ResizeObserver(onResize))); |
243 | | - const parentMounted = (parent: Element | not) => parent && resizeObserver?.observe(parent); |
244 | | - const parentUnmounted = (parent: Element | not) => parent && resizeObserver?.unobserve(parent); |
| 244 | + const parentMounted = (parent: Element | undefined) => parent && resizeObserver?.observe(parent); |
| 245 | + const parentUnmounted = (parent: Element | undefined) => |
| 246 | + parent && resizeObserver?.unobserve(parent); |
245 | 247 |
|
246 | 248 | function onResize() { |
247 | 249 | if (!parent || !element) return; |
|
0 commit comments