Cleaner modifyState usage (please avoid using cotransform)

parent 28f1450d
......@@ -9,7 +9,7 @@ import Data.Tuple (Tuple(..))
import React (ReactElement)
import React.DOM (a, div, nav, text)
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
......@@ -34,8 +34,7 @@ tab sid iid (Tuple name spec) = over _render tabRender spec
performAction :: forall props. PerformAction State props Action
performAction (ChangeTab i) _ _ = void do
cotransform \_ -> i
performAction (ChangeTab i) _ _ = void $ modifyState $ const i
render :: forall state props action. State -> List (Tuple String (Spec state props action)) -> Render State props Action
render at ls d p s c =
......
......@@ -19,7 +19,7 @@ import Effect.Console (log)
import React (ReactElement)
import React.DOM (a, div, i, li, text, ul)
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 Open = Boolean
......@@ -38,8 +38,7 @@ initialState :: State
initialState = NTree (LNode {id : 1, name : "", nodeType : "", open : true}) []
performAction :: PerformAction State {} Action
performAction (ToggleFolder i) _ _ = void $
cotransform (\td -> toggleNode i td)
performAction (ToggleFolder i) _ _ = void $ modifyState $ toggleNode i
-- performAction Initialize _ _ = void $ do
-- s <- lift $ loadDefaultNode
......
......@@ -32,7 +32,7 @@ performAction (ChangeString ps) _ _ = pure unit
performAction (ChangeAnotherString ps) _ _ = pure unit
performAction (SetInput ps) _ _ = void do
modifyState \( state) -> state { inputValue = ps }
modifyState $ _ { inputValue = ps }
......
......@@ -5,7 +5,7 @@ import Data.Array (fold)
import Gargantext.Pages.Corpus.Doc.Facets.Documents as D
import Prelude hiding (div)
import React.DOM (h3, text)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, modifyState, simpleSpec)
import Thermite (PerformAction, Render, Spec, defaultPerformAction, simpleSpec)
type State = D.State
......
......@@ -22,7 +22,7 @@ import Gargantext.Utils.DecodeMaybe ((.|))
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.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)
......@@ -182,15 +182,15 @@ layoutDocview = simpleSpec performAction render
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
res <- lift $ loadPage
case res of
Left err -> pure unit
Right resData -> void $ modifyState (\s -> resData)
Right resData -> void $ modifyState $ const resData
loadPage :: Aff (Either String CorpusTableData)
......
......@@ -4,7 +4,7 @@ import Data.Array (fold)
import Gargantext.Pages.Corpus.Doc.Facets.Documents as D
import Prelude hiding (div)
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)
import Data.Unit (Unit)
import Effect (Effect)
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.DOM hiding (style, map)
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)
newtype State = State
......@@ -62,7 +62,7 @@ type Dispatch = Action -> Effect Unit
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
modifyState \(State state) -> State $ state {currentPage = p}
......@@ -76,8 +76,7 @@ performAction (ChangeString c) _ _ = void do
performAction (SetInput s) _ _ = void do
modifyState \(State state) -> State $ state { search = s }
performAction _ _ _ = void do
modifyState \(State state) -> State $ state
performAction _ _ _ = pure unit
tableSpec :: Spec State {} Action -> Spec State {} Action
tableSpec = over _render \render dispatch p (State s) c ->
......
......@@ -4,7 +4,7 @@ import Prelude
import Control.Monad.Trans.Class (lift)
import Data.Either (Either(..))
import Data.Lens (set)
import Data.Lens ((?~))
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff)
import Effect.Class (liftEffect)
......@@ -21,7 +21,7 @@ performAction :: PerformAction State {} Action
performAction (FetchUser userId) _ _ = do
value <- lift $ getUser userId
_ <- case value of
(Right user) -> void $ modifyState \state -> set _user (Just user) state
(Right user) -> void $ modifyState $ _user ?~ user
(Left err) -> do
liftEffect $ log err
liftEffect <<< log $ "Fetching user..."
......
......@@ -28,17 +28,17 @@ data Action
performAction :: PerformAction State {} Action
performAction (SelectDatabase selected) _ _ = void do
modifyState \( state) -> state { select_database = selected }
modifyState $ _ { select_database = selected }
performAction (UnselectDatabase unselected) _ _ = void do
modifyState \( state) -> state { unselect_database = unselected }
modifyState $ _ { unselect_database = unselected }
performAction (LoadDatabaseDetails) _ _ = do
res <- lift $ getDatabaseDetails $ QueryString { query_query: "string",query_name: ["Pubmed"]}
case res of
Left err -> pure unit
Right resData -> do
void $ modifyState $ \(state) -> state {response = resData}
void $ modifyState $ _ {response = resData}
performAction GO _ _ = do
liftEffect $ setHash "/corpus"
......
......@@ -21,7 +21,7 @@ import Gargantext.Components.Modals.Modal (modalHide)
import React (ReactElement)
import React.DOM (button, div, h3, h5, li, span, text, ul)
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
......
......@@ -29,7 +29,7 @@ data Action
performAction :: PerformAction State {} Action
performAction (SetQuery q) _ _ = void do
modifyState \( state) -> state { query = q }
modifyState $ _ { query = q }
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