Commit 8f7a1b8b authored by Przemyslaw Kaminski's avatar Przemyslaw Kaminski

[graph] kill sigmajs after component unmount

Also, stop force atlas to make sure there are no leaks.
parent 9f0a0a6a
......@@ -49,6 +49,15 @@ graphCpt = R.hooksComponent "G.C.Graph" cpt
cpt props _ = do
stageHooks props
R.useEffectOnce $ do
pure $ do
log "[graphCpt (Cleanup)]"
Sigmax.dependOnSigma (R.readRef props.sigmaRef) "[graphCpt (Cleanup)] no sigma" $ \sigma -> do
Sigma.stopForceAtlas2 sigma
log2 "[graphCpt (Cleanup)] forceAtlas stopped for" sigma
Sigma.kill sigma
log "[graphCpt (Cleanup)] sigma killed"
-- NOTE: This div is not empty after sigma initializes.
-- When we change state, we make it empty though.
--pure $ RH.div { ref: props.elRef, style: {height: "95%"} } []
......@@ -57,7 +66,7 @@ graphCpt = R.hooksComponent "G.C.Graph" cpt
Just el -> R.createPortal [] el
stageHooks props@{multiSelectEnabledRef, selectedNodeIds, sigmaRef, stage: (Init /\ setStage)} = do
R.useEffectOnce $ do
R.useEffectOnce' $ do
let rSigma = R.readRef props.sigmaRef
case Sigmax.readSigma rSigma of
......@@ -103,11 +112,7 @@ graphCpt = R.hooksComponent "G.C.Graph" cpt
setStage $ const Ready
delay unit $ \_ -> do
log "[graphCpt] cleanup"
pure $ pure unit
stageHooks props@{showEdges: (showEdges /\ _), sigmaRef, stage: (Ready /\ setStage), transformedGraph} = do
stageHooks props@{ showEdges: (showEdges /\ _), sigmaRef, stage: (Ready /\ setStage), transformedGraph } = do
let tEdgesMap = SigmaxTypes.edgesGraphMap transformedGraph
let tNodesMap = SigmaxTypes.nodesGraphMap transformedGraph
......
......@@ -46,6 +46,10 @@ type SigmaOpts s = { settings :: s }
sigma :: forall opts err. SigmaOpts opts -> Effect (Either err Sigma)
sigma = runEffectFn3 _sigma Left Right
-- | Kill a sigmajs instance.
kill :: Sigma -> Effect Unit
kill sigma = pure $ sigma ... "kill" $ []
-- | Call the `refresh()` method on a sigmajs instance.
refresh :: Sigma -> Effect Unit
refresh s = pure $ s ... "refresh" $ []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment