File size: 989 Bytes
be5030f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { onMount, afterUpdate } from "svelte";
import { Streamlit } from "./streamlit";

/**
 * [Optional] Set Streamlit Svelte Lifecycle functions
 *
 * You are not required call this function on your Streamlit
 * component. If you decide not to call it, you should implement the
 * `onMount` and `afterUpdate` functions in your own component,
 * so that your plugin properly resizes.
 */
export const setStreamlitLifecycle = (): void => {
  onMount((): void => {
    // Finally, tell Streamlit to update our initial height. We omit the
    // `height` parameter here to have it default to our scrollHeight.
    Streamlit.setFrameHeight();
  });

  afterUpdate((): void => {
    // We tell Streamlit to update our frameHeight after each update, in
    // case it has changed. (This isn't strictly necessary for the example
    // because our height stays fixed, but this is a low-cost function, so
    // there's no harm in doing it redundantly.)
    Streamlit.setFrameHeight();
  });
};