Added onInit and useInitialized hooks
This commit is contained in:
@@ -77,6 +77,7 @@
|
||||
export let onconnectstart: $$Props['onconnectstart'] = undefined;
|
||||
export let onconnectend: $$Props['onconnectend'] = undefined;
|
||||
export let onbeforedelete: $$Props['onbeforedelete'] = undefined;
|
||||
export let oninit: $$Props['oninit'] = undefined;
|
||||
|
||||
export let defaultMarkerColor = '#b1b1b7';
|
||||
|
||||
@@ -130,6 +131,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Call oninit once when flow is intialized
|
||||
const { initialized } = store;
|
||||
let onInitCalled = false;
|
||||
$: {
|
||||
if (!onInitCalled && $initialized) {
|
||||
oninit?.();
|
||||
onInitCalled = true;
|
||||
}
|
||||
}
|
||||
|
||||
// this updates the store for simple changes
|
||||
// where the prop names equals the store name
|
||||
$: {
|
||||
|
||||
@@ -333,4 +333,6 @@ export type SvelteFlowProps = DOMAttributes<HTMLDivElement> & {
|
||||
onconnectstart?: OnConnectStart;
|
||||
/** When a user stops dragging a connection line, this event gets fired. */
|
||||
onconnectend?: OnConnectEnd;
|
||||
/** This handler gets called when the flow is finished initializing */
|
||||
oninit?: () => void;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user