Tweak debuging code

parent e2f88a6d
...@@ -37,6 +37,7 @@ type State path loaded = { currentPath :: path, loaded :: Maybe loaded } ...@@ -37,6 +37,7 @@ type State path loaded = { currentPath :: path, loaded :: Maybe loaded }
createLoaderClass' :: forall path loaded props createLoaderClass' :: forall path loaded props
. Eq path . Eq path
=> Show path
=> String => String
-> (path -> Aff loaded) -> (path -> Aff loaded)
-> Render (State path loaded) {path :: path | props} (Action path) -> Render (State path loaded) {path :: path | props} (Action path)
...@@ -44,12 +45,16 @@ createLoaderClass' :: forall path loaded props ...@@ -44,12 +45,16 @@ createLoaderClass' :: forall path loaded props
createLoaderClass' name loader render = createLoaderClass' name loader render =
React.component name React.component name
(\this -> do (\this -> do
logs $ "createLoaderClass' " <> name
s <- spec this s <- spec this
pure { state: s.state pure { state: s.state
, render: s.render , render: s.render
, componentDidMount: dispatcher this ForceReload , componentDidMount: do
, componentDidUpdate: \_prevProps {currentPath} _snapshot -> do logs $ name <> ".componentDidMount"
dispatcher this ForceReload
, componentDidUpdate: \{path: prevPath} {currentPath} _snapshot -> do
{path} <- React.getProps this {path} <- React.getProps this
logs $ name <> ".componentDidUpdate " <> show {currentPath, path, prevPath}
-- This guard is the same as in performAction (SetPath ...), -- This guard is the same as in performAction (SetPath ...),
-- however we need it here to avoid potential infinite loops. -- however we need it here to avoid potential infinite loops.
-- https://reactjs.org/docs/react-component.html#componentdidupdate -- https://reactjs.org/docs/react-component.html#componentdidupdate
...@@ -61,9 +66,11 @@ createLoaderClass' name loader render = ...@@ -61,9 +66,11 @@ createLoaderClass' name loader render =
performAction :: PerformAction (State path loaded) {path :: path | props} (Action path) performAction :: PerformAction (State path loaded) {path :: path | props} (Action path)
performAction ForceReload _ {currentPath} = do performAction ForceReload _ {currentPath} = do
logs $ name <> ".ForceReload {currentPath: " <> show currentPath <> "}"
loaded <- lift $ loader currentPath loaded <- lift $ loader currentPath
modifyState_ $ _ { loaded = Just loaded } modifyState_ $ _ { loaded = Just loaded }
performAction (SetPath newPath) _ {currentPath} = performAction (SetPath newPath) _ {currentPath} = do
logs $ name <> ".SetPath " <> show {newPath, currentPath}
when (newPath /= currentPath) do when (newPath /= currentPath) do
loaded <- lift $ loader newPath loaded <- lift $ loader newPath
modifyState_ $ _ { currentPath = newPath, loaded = Just loaded } modifyState_ $ _ { currentPath = newPath, loaded = Just loaded }
...@@ -75,6 +82,7 @@ type LoaderClass path loaded = ...@@ -75,6 +82,7 @@ type LoaderClass path loaded =
createLoaderClass :: forall path loaded createLoaderClass :: forall path loaded
. Eq path . Eq path
=> Show path
=> String => String
-> (path -> Aff loaded) -> (path -> Aff loaded)
-> LoaderClass path loaded -> LoaderClass path loaded
......
...@@ -131,6 +131,7 @@ tableSpec = simpleSpec performAction render ...@@ -131,6 +131,7 @@ tableSpec = simpleSpec performAction render
where where
modifyStateAndReload :: (State -> State) -> Props -> State -> StateCoTransformer State Unit modifyStateAndReload :: (State -> State) -> Props -> State -> StateCoTransformer State Unit
modifyStateAndReload f {setParams} state = do modifyStateAndReload f {setParams} state = do
logs "modifyStateAndReload" -- TODO rename
modifyState_ f modifyState_ f
liftEffect $ setParams $ stateParams $ f state liftEffect $ setParams $ stateParams $ f state
......
...@@ -197,8 +197,8 @@ loadPage {nodeId, params: {limit, offset, orderBy}} = do ...@@ -197,8 +197,8 @@ loadPage {nodeId, params: {limit, offset, orderBy}} = do
--res <- get $ toUrl Back (Children Url_Document offset limit) nodeId --res <- get $ toUrl Back (Children Url_Document offset limit) nodeId
res <- get $ toUrl Back (Tab TabDocs offset limit (convOrderBy <$> orderBy)) (Just nodeId) res <- get $ toUrl Back (Tab TabDocs offset limit (convOrderBy <$> orderBy)) (Just nodeId)
let docs = res2corpus <$> res let docs = res2corpus <$> res
_ <- logs "Ok: loading page documents" --_ <- logs "Ok: loading page documents"
_ <- logs $ map show docs --_ <- logs $ map show docs
pure $ pure $
if mock then take limit $ drop offset sampleData else if mock then take limit $ drop offset sampleData else
docs docs
......
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