Closed mrozbarry closed 7 years ago
I updated your code to make it work: https://gist.github.com/gdotdesign/31cde4cd3fd12fbac89341415fc5101a/revisions#diff-ac0369f042f6f2f81847c72c5fa3145e
There were two logical errors in it:
Most components in Elm-UI have unique ids and to generate them it uses native code and it's used to publish events for a component, so by doing this:
datePicker : Ui.DatePicker.Model
datePicker =
Ui.DatePicker.init (Ext.Date.now ())
you create one record, and if you use this many times it will "broadcast" to the same channel. This can be solved by giving the function a dummy parameter:
datePicker : () -> Ui.DatePicker.Model
datePicker () =
Ui.DatePicker.init (Ext.Date.now ())
The second one is using records in messages. There was a race condition between the subscribe and the messages of a datepicker, and since the records from the message were used instead of the ones in the model the state of the application was instabil, to demonstrate this:
If you need more explanation let me know, I'll try to explain them better.
@gdotdesign should I be using a similar pattern for Ui.Chooser messages (I posted an example a day or two ago as a separate issue) - what I mean is, should I be doing something like:
replaceChooser : MyChooser -> (MyChooser, Cmd Msg)
replaceChooser chooser =
if chooser.id == changedId
let
( uiChooser, effect ) = Ui.Chooser.update subMsg chooser.uiChooser
in
( { chooser | uiChooser = uiChooser }, Cmd.map (UiChooserMessage changedId) effect)
else
( chooser, Cmd.none )
It would be great if you could add some examples of this in your documentation - I'm definitely not the best when it comes to elm, but if I got stuck on it, someone else is bound to eventually, too.
I just integrated into my test app locally, and everything is looking great. Thanks, I spun my wheels on this for a few hours yesterday, so I'm very appreciative of your help and getting back to me quickly!
It would be great if you could add some examples of this in your documentation
This is not really an Elm-UI issue more like a general language one, however it could fit in a page like "best practices".
I just integrated into my test app locally, and everything is looking great. Thanks, I spun my wheels on this for a few hours yesterday, so I'm very appreciative of your help and getting back to me quickly!
I'm glad it works :)
I've run into a problem subscribing to events and changes using Ui.DatePicker. I have a model that has a list of
{ Int, Ui.DatePicker.Model, String }
where int is my own index/identifier, and string just converts the date picker selection into iso8601 for test purposes. When I don't use a list, everything seems to work fine. Once I introduce the list, even with a single element on it, I'm no longer able to see the select event and build my iso8601 string.Another compound issue is that I'm not able to change months in the calendar picker.
I've built a minimal example here, and was wondering if this boils down to a problem with my implementation, or if there is a bug in elm-ui. Any help would be appreciated.