Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/matheus23/please-focus-more
Some helpful setters (a.k.a. Lenses/foci) using and extending please-focus
https://github.com/matheus23/please-focus-more
Last synced: 18 days ago
JSON representation
Some helpful setters (a.k.a. Lenses/foci) using and extending please-focus
- Host: GitHub
- URL: https://github.com/matheus23/please-focus-more
- Owner: matheus23
- Created: 2017-08-08T19:08:45.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2017-08-08T19:09:39.000Z (about 7 years ago)
- Last Synced: 2024-10-08T09:18:29.709Z (28 days ago)
- Language: Elm
- Size: 1.95 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Focus More
Adds a couple of helpful "Setters" (or "Lenses" or "Foci" or whatever).
This library is ment as a small extension of the `SwiftNamesake/please-focus` package.
Usually imported together like this:```elm
import Focus exposing (Setter, (&), (.=), (=>), ($=))
import FocusMore as Focus exposing (FieldSetter)
```Also here's my free trick for handling Union-type Models:
```elm
import Focus
import FocusMore as Focustype alias InActionModel = ...
type alias NotInActionModel = ...
type Model
= UserInAction InActionModel
| NotInAction NotInActionModel-- Define the "Setters" which only set,
-- when the model is in the respective case
userInAction : Focus.FieldSetter Model InActionModel
userInAction f model =
case model of
UserInAction inAction ->
UserInAction (f inAction)_ ->
modelnotInAction : Focus.FieldSetter Model NotInActionModel
notInAction f model =
case model of
NotInAction notInAction ->
NotInAction (f notInAction)_ ->
model
```Now you can use these Setters in your update function:
```elm
update : ...
update msg model =
case msg of
UserActionMsg actionMsg ->
model & userInAction $= updateInAction actionMsg... ->
...
```