Cleaner modifyState usage (please avoid using cotransform)

parent 28f1450d
...@@ -9,7 +9,7 @@ import Data.Tuple (Tuple(..)) ...@@ -9,7 +9,7 @@ import Data.Tuple (Tuple(..))
import React (ReactElement) import React (ReactElement)
import React.DOM (a, div, nav, text) import React.DOM (a, div, nav, text)
import React.DOM.Props (className, onClick) import React.DOM.Props (className, onClick)
import Thermite (PerformAction, Render, Spec, _render, cotransform, focus, simpleSpec, withState) import Thermite (PerformAction, Render, Spec, _render, modifyState, focus, simpleSpec, withState)
type State = Int type State = Int
...@@ -34,8 +34,7 @@ tab sid iid (Tuple name spec) = over _render tabRender spec ...@@ -34,8 +34,7 @@ tab sid iid (Tuple name spec) = over _render tabRender spec
performAction :: forall props. PerformAction State props Action performAction :: forall props. PerformAction State props Action
performAction (ChangeTab i) _ _ = void do performAction (ChangeTab i) _ _ = void $ modifyState $ const i
cotransform \_ -> i
render :: forall state props action. State -> List (Tuple String (Spec state props action)) -> Render State props Action render :: forall state props action. State -> List (Tuple String (Spec state props action)) -> Render State props Action
render at ls d p s c = render at ls d p s c =
......
...@@ -19,7 +19,7 @@ import Effect.Console (log) ...@@ -19,7 +19,7 @@ import Effect.Console (log)
import React (ReactElement) import React (ReactElement)
import React.DOM (a, div, i, li, text, ul) import React.DOM (a, div, i, li, text, ul)
import React.DOM.Props (Props, className, href, onClick) import React.DOM.Props (Props, className, href, onClick)
import Thermite (PerformAction, Render, Spec, cotransform, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, modifyState, simpleSpec)
type Name = String type Name = String
type Open = Boolean type Open = Boolean
...@@ -38,8 +38,7 @@ initialState :: State ...@@ -38,8 +38,7 @@ initialState :: State
initialState = NTree (LNode {id : 1, name : "", nodeType : "", open : true}) [] initialState = NTree (LNode {id : 1, name : "", nodeType : "", open : true}) []
performAction :: PerformAction State {} Action performAction :: PerformAction State {} Action
performAction (ToggleFolder i) _ _ = void $ performAction (ToggleFolder i) _ _ = void $ modifyState $ toggleNode i
cotransform (\td -> toggleNode i td)
-- performAction Initialize _ _ = void $ do -- performAction Initialize _ _ = void $ do
-- s <- lift $ loadDefaultNode -- s <- lift $ loadDefaultNode
......
...@@ -32,7 +32,7 @@ performAction (ChangeString ps) _ _ = pure unit ...@@ -32,7 +32,7 @@ performAction (ChangeString ps) _ _ = pure unit
performAction (ChangeAnotherString ps) _ _ = pure unit performAction (ChangeAnotherString ps) _ _ = pure unit
performAction (SetInput ps) _ _ = void do performAction (SetInput ps) _ _ = void do
modifyState \( state) -> state { inputValue = ps } modifyState $ _ { inputValue = ps }
......
...@@ -5,7 +5,7 @@ import Data.Array (fold) ...@@ -5,7 +5,7 @@ import Data.Array (fold)
import Gargantext.Pages.Corpus.Doc.Facets.Documents as D import Gargantext.Pages.Corpus.Doc.Facets.Documents as D
import Prelude hiding (div) import Prelude hiding (div)
import React.DOM (h3, text) import React.DOM (h3, text)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec)
type State = D.State type State = D.State
......
...@@ -22,7 +22,7 @@ import Gargantext.Utils.DecodeMaybe ((.|)) ...@@ -22,7 +22,7 @@ import Gargantext.Utils.DecodeMaybe ((.|))
import React (ReactElement) import React (ReactElement)
import React.DOM (a, b, b', br', div, input, option, select, span, table, tbody, td, text, th, thead, tr) import React.DOM (a, b, b', br', div, input, option, select, span, table, tbody, td, text, th, thead, tr)
import React.DOM.Props (_type, className, href, onChange, onClick, scope, selected, value) import React.DOM.Props (_type, className, href, onChange, onClick, scope, selected, value)
import Thermite (PerformAction, Render, Spec, cotransform, defaultPerformAction, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, modifyState, defaultPerformAction, simpleSpec)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
...@@ -182,15 +182,15 @@ layoutDocview = simpleSpec performAction render ...@@ -182,15 +182,15 @@ layoutDocview = simpleSpec performAction render
performAction :: PerformAction State {} Action performAction :: PerformAction State {} Action
performAction (ChangePageSize ps) _ _ = void (cotransform (\state -> changePageSize ps state )) performAction (ChangePageSize ps) _ _ = void $ modifyState $ changePageSize ps
performAction (ChangePage p) _ _ = void (cotransform (\(TableData td) -> TableData $ td { currentPage = p} )) performAction (ChangePage p) _ _ = void $ modifyState \(TableData td) -> TableData $ td { currentPage = p }
performAction LoadData _ _ = do performAction LoadData _ _ = do
res <- lift $ loadPage res <- lift $ loadPage
case res of case res of
Left err -> pure unit Left err -> pure unit
Right resData -> void $ modifyState (\s -> resData) Right resData -> void $ modifyState $ const resData
loadPage :: Aff (Either String CorpusTableData) loadPage :: Aff (Either String CorpusTableData)
......
...@@ -4,7 +4,7 @@ import Data.Array (fold) ...@@ -4,7 +4,7 @@ import Data.Array (fold)
import Gargantext.Pages.Corpus.Doc.Facets.Documents as D import Gargantext.Pages.Corpus.Doc.Facets.Documents as D
import Prelude hiding (div) import Prelude hiding (div)
import React.DOM (h3, text) import React.DOM (h3, text)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec)
......
...@@ -13,11 +13,11 @@ import Data.Void (Void) ...@@ -13,11 +13,11 @@ import Data.Void (Void)
import Data.Unit (Unit) import Data.Unit (Unit)
import Effect (Effect) import Effect (Effect)
import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsItem as NI import Gargantext.Pages.Corpus.Doc.Facets.Terms.NgramsItem as NI
import Prelude (class Eq, class Ord, class Show, map, show, void, ($), (*), (+), (-), (/), (<), (<>), (==), (>), (>=)) import Prelude (class Eq, class Ord, class Show, map, show, void, ($), (*), (+), (-), (/), (<), (<>), (==), (>), (>=), pure, unit)
import React (ReactElement) import React (ReactElement)
import React.DOM hiding (style, map) import React.DOM hiding (style, map)
import React.DOM.Props (_id, _type, className, href, name, onChange, onClick, onInput, placeholder, scope, selected, style, value) import React.DOM.Props (_id, _type, className, href, name, onChange, onClick, onInput, placeholder, scope, selected, style, value)
import Thermite (PerformAction, Spec, _render, cotransform, focus, foreach, modifyState, focusState, hide) import Thermite (PerformAction, Spec, _render, focus, foreach, modifyState, focusState, hide)
import Unsafe.Coerce (unsafeCoerce) import Unsafe.Coerce (unsafeCoerce)
newtype State = State newtype State = State
...@@ -62,7 +62,7 @@ type Dispatch = Action -> Effect Unit ...@@ -62,7 +62,7 @@ type Dispatch = Action -> Effect Unit
performAction :: PerformAction State {} Action performAction :: PerformAction State {} Action
performAction (ChangePageSize ps) _ _ = void (cotransform (\state -> changePageSize ps state )) performAction (ChangePageSize ps) _ _ = void $ modifyState $ changePageSize ps
performAction (ChangePage p) _ _ = void do performAction (ChangePage p) _ _ = void do
modifyState \(State state) -> State $ state {currentPage = p} modifyState \(State state) -> State $ state {currentPage = p}
...@@ -76,8 +76,7 @@ performAction (ChangeString c) _ _ = void do ...@@ -76,8 +76,7 @@ performAction (ChangeString c) _ _ = void do
performAction (SetInput s) _ _ = void do performAction (SetInput s) _ _ = void do
modifyState \(State state) -> State $ state { search = s } modifyState \(State state) -> State $ state { search = s }
performAction _ _ _ = void do performAction _ _ _ = pure unit
modifyState \(State state) -> State $ state
tableSpec :: Spec State {} Action -> Spec State {} Action tableSpec :: Spec State {} Action -> Spec State {} Action
tableSpec = over _render \render dispatch p (State s) c -> tableSpec = over _render \render dispatch p (State s) c ->
......
...@@ -4,7 +4,7 @@ import Prelude ...@@ -4,7 +4,7 @@ import Prelude
import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Class (lift)
import Data.Either (Either(..)) import Data.Either (Either(..))
import Data.Lens (set) import Data.Lens ((?~))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Effect.Aff (Aff) import Effect.Aff (Aff)
import Effect.Class (liftEffect) import Effect.Class (liftEffect)
...@@ -21,7 +21,7 @@ performAction :: PerformAction State {} Action ...@@ -21,7 +21,7 @@ performAction :: PerformAction State {} Action
performAction (FetchUser userId) _ _ = do performAction (FetchUser userId) _ _ = do
value <- lift $ getUser userId value <- lift $ getUser userId
_ <- case value of _ <- case value of
(Right user) -> void $ modifyState \state -> set _user (Just user) state (Right user) -> void $ modifyState $ _user ?~ user
(Left err) -> do (Left err) -> do
liftEffect $ log err liftEffect $ log err
liftEffect <<< log $ "Fetching user..." liftEffect <<< log $ "Fetching user..."
......
...@@ -28,17 +28,17 @@ data Action ...@@ -28,17 +28,17 @@ data Action
performAction :: PerformAction State {} Action performAction :: PerformAction State {} Action
performAction (SelectDatabase selected) _ _ = void do performAction (SelectDatabase selected) _ _ = void do
modifyState \( state) -> state { select_database = selected } modifyState $ _ { select_database = selected }
performAction (UnselectDatabase unselected) _ _ = void do performAction (UnselectDatabase unselected) _ _ = void do
modifyState \( state) -> state { unselect_database = unselected } modifyState $ _ { unselect_database = unselected }
performAction (LoadDatabaseDetails) _ _ = do performAction (LoadDatabaseDetails) _ _ = do
res <- lift $ getDatabaseDetails $ QueryString { query_query: "string",query_name: ["Pubmed"]} res <- lift $ getDatabaseDetails $ QueryString { query_query: "string",query_name: ["Pubmed"]}
case res of case res of
Left err -> pure unit Left err -> pure unit
Right resData -> do Right resData -> do
void $ modifyState $ \(state) -> state {response = resData} void $ modifyState $ _ {response = resData}
performAction GO _ _ = do performAction GO _ _ = do
liftEffect $ setHash "/corpus" liftEffect $ setHash "/corpus"
......
...@@ -21,7 +21,7 @@ import Gargantext.Components.Modals.Modal (modalHide) ...@@ -21,7 +21,7 @@ import Gargantext.Components.Modals.Modal (modalHide)
import React (ReactElement) import React (ReactElement)
import React.DOM (button, div, h3, h5, li, span, text, ul) import React.DOM (button, div, h3, h5, li, span, text, ul)
import React.DOM.Props (_data, _id, _type, aria, className, onClick, role) import React.DOM.Props (_data, _id, _type, aria, className, onClick, role)
import Thermite (PerformAction, Render, Spec, _render, cotransform, modifyState, simpleSpec) import Thermite (PerformAction, Render, Spec, _render, simpleSpec)
modalSpec :: Boolean -> String -> Spec State {} Action -> Spec State {} Action modalSpec :: Boolean -> String -> Spec State {} Action -> Spec State {} Action
......
...@@ -29,7 +29,7 @@ data Action ...@@ -29,7 +29,7 @@ data Action
performAction :: PerformAction State {} Action performAction :: PerformAction State {} Action
performAction (SetQuery q) _ _ = void do performAction (SetQuery q) _ _ = void do
modifyState \( state) -> state { query = q } modifyState $ _ { query = q }
performAction GO _ _ = void do performAction GO _ _ = void do
......
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