Comments (9)
I do not have a solution, but I asked myself the same question. My "solution" so far is to modify elm-mdl's source to expose Msg(ToggleDrawer)
, so that I can do
Layout.update Layout.ToggleDrawer model.layout
|> Helpers.map1st (\layout -> { model | layout = layout })
|> Helpers.map2nd LayoutMsg
in my application's update
function. I am guessing things like that have not been fleshed out with elm-mdl yet, and one will have to investigate a general solution for that for all elm-mdl components.
Personally, I wouldn't mind if all components export Msg(..)
and every handled event is completely overidable, ie. preventing default behaviour and executing with a custom Decoder a
.
from elm-mdl.
@aforemny : @shmish111 is using parts, so he don't have direct access to update. I'll think about this and try to come up with a good solution in a couple of days.
from elm-mdl.
I'll release a new version shortly, in which (a) ToggleDrawer is exposed (for @aforemny) and (b) there is a value toggleDrawer
such that toggleDrawer Mdl
will be an action of the appropriate type. I.e., from your update function, you may toggle the drawer with:
update action model =
case action of
...
MyToggleAction ->
update (Layout.toggleDrawer Mdl) model
from elm-mdl.
@debois I don't quite understand the usage, what is update
and model
in your example? Material.update
? model
is my model.materialModel
?
I can't get it to compile, still not understanding parts properly :(
from elm-mdl.
No worries. Could you post a link to a gist or github where I can see what you're trying to do?
from elm-mdl.
@debois OK, I think I understand what's going on now but now that I got everything compiling the toggle doesn't actually seem to work :(
In my update
function I have
SelectSearch search ->
let
(updatedModel, cmd) = update (Layout.toggleDrawer MDL) model
in
( { updatedModel | currentSearch = search }
, cmd
)
where MDL
is my Msg
type, i.e. | MDL Material.Msg
For parts to work I also have this in my update
function
MDL action' ->
Material.update MDL action' model
Using Debug
I can see that update is called with SelectSearch
correctly and then with MDL (Msg <function>)
as I expected. However the drawer is still shown :(
from elm-mdl.
Ok, so I understand the problem now and I've fixed it but I don't know how to structure the app with parts to make it nice. My update
function is actually a sub module called using the normal TEA way. In order to use Layout
stuff in my view, my child module's model has the mdl model from the parent. In my parent update
function I have to pass the mdl to the child update and then update the parent mdl, it all seems a bit too much boiler plate.
My Main.elm update function:
SearchesMsg action' ->
let
searchesModel =
model.searchesModel
( updatedSearchesModel, searchesCmd ) =
Searches.update action' { searchesModel | mdl = model.mdl }
in
( { model
| searchesModel = updatedSearchesModel
, currentView = SearchView
, mdl = updatedSearchesModel.mdl
}
, Cmd.map SearchesMsg searchesCmd
)
Is there a better way to do this?
from elm-mdl.
I think a more idiomatic way would be to have your sub-module communicate its desire to toggle the drawer in the normal TEA-way (e.g., the parent intercepts some Msg
of the sub, then invokes toggleDrawer
on its mdl
model).
Parts don't really solve the inter-component communication boilerplate problem. They just make it more convenient to have (independent) sub-components.
from elm-mdl.
My worked example:
type alias Model =
{mdl : Material.Model
, myfields ...
}
...
viewDrawer:
Layout.link
[ Options.onClick (FilterCategory category) -- it is toggle Action
...
type Msg =
FilterCategory Category
...
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
FilterCategory category ->
let
catalog =
model.catalog
mdl =
model.mdl
( updatedModel, updateDrawerCmd ) =
update (Layout.toggleDrawer Mdl) model
in
({ model
| catalog =
{ catalog
| filterCategory = category.name
}
, mdl = updatedModel.mdl
}
! [ API.Product.forCategory LoadProducts category.id
, updateDrawerCmd
]
)
from elm-mdl.
Related Issues (20)
- Dialog closes automatically
- Ripple effect on custom elements
- Hide function not working
- Chips don't work as in the demo app interactive part
- elm-make.exe: getFileAttributesExStandard: does not exist
- Can't change table size HOT 2
- Tabs Overcomplexity
- Textfield floating / placeholders don't disapear. HOT 1
- Toggles don't have a `Toggles.error` option.
- Table.numeric is applying non-numeric css HOT 3
- demo broken HOT 2
- No checkbox disabled visual feedback. HOT 1
- Select dropdown doesn't redraw dropdown size when elements are added to it
- bug, there is a missing parentesis in generated javascript HOT 3
- Menu doesn't show properly when used in a list item
- Expose / Reexport exposed types from Component
- Toggles don't trigger `is-focused` class on focus
- Library continuity HOT 7
- Label does not float when I provide an Options.onInput HOT 6
- Elm 0.19 support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elm-mdl.