Skip to content

Commit

Permalink
feat(Carpenter): add defaultUpdate
Browse files Browse the repository at this point in the history
`defaultUpdate` is a default implementation of the update function which ignores all actions
  • Loading branch information
arthurxavierx committed Sep 22, 2016
1 parent f96ae45 commit 3f20fc7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/Carpenter.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ spec' :: forall state props action eff. state -> action -> Update state props ac
Constructs a React component spec based on an initial state,
an initial action, an update function and a render function.

#### `defaultUpdate`

``` purescript
defaultUpdate :: forall state props action eff. Update state props action eff
```

A default implementation for the update function which does not perform
any changes to the state, that is, ignores all actions.

#### `mockUpdate`

``` purescript
Expand Down
6 changes: 6 additions & 0 deletions src/Carpenter.purs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Carpenter
, EventHandler
, ActionHandler
, CarpenterEffects
, defaultUpdate
, mockUpdate
) where

Expand Down Expand Up @@ -87,6 +88,11 @@ spec' state action update render = (React.spec state (getReactRender update rend
let dispatch = mkDispatcher this update yield
unsafeInterleaveEff (launchAff (update yield dispatch action props state))

-- | A default implementation for the update function which does not perform
-- | any changes to the state, that is, ignores all actions.
defaultUpdate :: state props action eff. Update state props action eff
defaultUpdate _ _ _ _ = pure

-- | Generates an update function for testing with mock `yield` and `dispatch`
-- | functions, which do not depend on React, but return the modified state and
-- | behave as expected.
Expand Down

0 comments on commit 3f20fc7

Please sign in to comment.