Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to handle events thrown by custom components. #94

Closed
wants to merge 1 commit into from

Conversation

chexxor
Copy link
Contributor

@chexxor chexxor commented Dec 21, 2016

I think Pux needs an evt function to allow users to respond to events containing arbitrarily-shaped data, as third-party components often fire uniquely-shaped events. This is similar to the attr function, which already exists in this library. What do you think?

Details of my use-case follows.

I imported the React Bootstrap Datepicker components into my project, using the Pux.fromReact function, and I want to respond to the onChange event it fires. The type of the event it throws is unlike any event defined in this repo, it is type DatePickerSelectEvent = String, where the String is the ISO-encoded date which was selected.

Here's the relevant snippets from my project, which might clarify.

import App.ReactBootstrap.Components as RBC
...
type DatePickerSelectEvent = String
data Action = x | y | ChangeReservationDate DatePickerSelectEvent
...
update (ChangeReservationDate newDate) state = noEffects $ state { reservationDate = newDate }
...
view state =
  form [ onSubmit (ReservationViewChange) ]
    [ formGroup [ attr "controlId" "reservationDate" ]
      [ controlLabel []
        [ text "Reservation Date" ]
      , RBC.datePicker [ attr "id" "reservation-datepicker",  value state.reservationDate, evt "onChange" ChangeReservationDate ]
        []
      ]
    , ...

@alexmingoia
Copy link
Owner

Released in Pux 7.2

@alexmingoia alexmingoia closed this Apr 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants