[websocket] use Ref for better state management

parent ecdeeed1
......@@ -62,6 +62,7 @@ workspace:
- reactix: ">=0.6.1 <0.7.0"
- record: ">=4.0.0 <5.0.0"
- record-extra: ">=5.0.1 <6.0.0"
- refs
- routing: ">=11.0.0 <12.0.0"
- sequences: "*"
- simple-json: ">=9.0.0 <10.0.0"
......
......@@ -105,6 +105,7 @@ package:
- reactix: ">=0.6.1 <0.7.0"
- record: ">=4.0.0 <5.0.0"
- record-extra: ">=5.0.1 <6.0.0"
- refs
- routing: ">=11.0.0 <12.0.0"
- sequences: "*"
- simple-json: ">=9.0.0 <10.0.0"
......
......@@ -16,6 +16,7 @@ import Gargantext.Types (CacheParams, defaultCacheParams)
import Gargantext.Utils (getter)
import Gargantext.Utils.Reactix as R2
import Reactix as R
import Reactix.Utils as RU
import Record as Record
import Toestand as T
......@@ -62,12 +63,14 @@ hydrateStoreCpt = here.component "hydrateStore" cpt where
} _ = do
-- | Computed
-- |
wsNotification <- RU.hook $ \_ -> Notifications.emptyWSNotification
(state :: Record AppStore.State) <- pure $
-- (cache options)
{ expandTableEdition: getter _.expandTableEdition cacheParams
, showTree: getter _.showTree cacheParams
-- (default options)
} `Record.merge` AppStore.options
} `Record.merge` (AppStore.options wsNotification)
-- | Render
-- |
......@@ -102,13 +105,13 @@ mainAppCpt = here.component "main" cpt where
R2.loadLocalStorageState R2.openNodesKey boxes.forestOpen
T.listen (R2.listenLocalStorageState R2.openNodesKey) boxes.forestOpen
R.useEffectOnce' $ do
ws' <- T.read boxes.wsNotification
ws <- T.read boxes.wsNotification
-- TODO See G.C.Forest: we need a WS connection for every backend we're connected to
(Sessions.Sessions { sessions }) <- T.read boxes.sessions
let session = Seq.head sessions
-- here.log2 "[mainApp] sessions" sessions'
ws <- Notifications.connect ws' "ws://localhost:8008/ws" session
T.write_ ws boxes.wsNotification
Notifications.connect ws "ws://localhost:8008/ws" session
-- T.write_ ws boxes.wsNotification
let action = Notifications.InsertCallback (Notifications.UpdateTree (-1)) "some-uuid" (\_ -> here.log "callback!")
Notifications.performAction ws action
useHashRouter Router.router boxes.route -- Install router to window
......
......@@ -33,6 +33,7 @@ import Gargantext.Utils.Reactix as R2
import Gargantext.Utils.Stores as Stores
import Gargantext.Utils.Toestand as T2
import Reactix as R
import Record as Record
import Toestand as T
import Unsafe.Coerce (unsafeCoerce)
......@@ -100,8 +101,9 @@ type State =
, wsNotification :: Notifications.WSNotification
)
options :: Record State
options =
options :: Notifications.WSNotification -> Record State
options wsNotification =
{ wsNotification } `Record.merge`
{ backend : Nothing
, errors : []
, expandTableEdition : false
......@@ -128,7 +130,6 @@ options =
, theme : Themes.defaultTheme
, tileAxisXList : mempty
, tileAxisYList : mempty
, wsNotification : Notifications.emptyWSNotification
}
context :: R.Context (Record Store)
......
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