Giter Site home page Giter Site logo

Toggle Drawer about elm-mdl HOT 9 CLOSED

shmish111 avatar shmish111 commented on September 25, 2024
Toggle Drawer

from elm-mdl.

Comments (9)

aforemny avatar aforemny commented on September 25, 2024

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.

debois avatar debois commented on September 25, 2024

@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.

debois avatar debois commented on September 25, 2024

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.

shmish111 avatar shmish111 commented on September 25, 2024

@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.

debois avatar debois commented on September 25, 2024

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.

shmish111 avatar shmish111 commented on September 25, 2024

@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.

shmish111 avatar shmish111 commented on September 25, 2024

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.

debois avatar debois commented on September 25, 2024

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.

dan-kihot8 avatar dan-kihot8 commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.