Coder Social home page Coder Social logo

Expose Msg with Msg(...) about toasty HOT 3 CLOSED

pablen avatar pablen commented on July 23, 2024
Expose Msg with Msg(...)

from toasty.

Comments (3)

pablen avatar pablen commented on July 23, 2024 1

Hello Gabriel! I'm a bit reluctant about exposing the whole Msg subtypes because then any internal change in the Msg implementation would imply a major version bump when publishing the package as explained here: https://medium.com/@ghivert/designing-api-in-elm-opaque-types-ce9d5f113033.

Maybe I can expose some helper functions like isTransitioning : Toasty.Msg -> Bool to let you extract the internal message.

Would that help with what you are trying to achieve?

from toasty.

gabrielperales avatar gabrielperales commented on July 23, 2024

Hi @pablen!, I ended creating those helpers functions, and I think it is ok. I was trying to create my own toast component which was just exactly as yours but without having to pass the config record to each function. Here you can see the code and how I exposed those helper functions.

If you think there is an approach better to achieve the same thing, please let me know it :)

from toasty.

pablen avatar pablen commented on July 23, 2024

Oh, so I think I misunderstood what you were trying to do here.

In your case I think those helper functions are a bit redundant because you can use the Success, Warning and Error types as constructor functions without the need of defining new helper functions.

You can take a look at the demo code, you'll notice I'm using those types in such a way:

case Char.fromCode keycode of
's' ->
(model ! [])
|> addToast (Toasty.Defaults.Success "Allright!" "Thing successfully updated")
'w' ->
(model ! [])
|> addToast (Toasty.Defaults.Warning "Warning!" "Please check this and that.")
'e' ->
(model ! [])
|> addToast (Toasty.Defaults.Error "Error" "Sorry, something went wrong...")

Also, look a few lines above how I defined a single addToast helper function to avoid having to pass the config record around every time:

addToast : Toasty.Defaults.Toast -> ( Model, Cmd Msg ) -> ( Model, Cmd Msg )
addToast toast ( model, cmd ) =
Toasty.addToast myConfig ToastyMsg toast ( model, cmd )

I think you'll be good to go with this!

from toasty.

Related Issues (7)

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.