Code Monkey home page Code Monkey logo

Comments (8)

alexmingoia avatar alexmingoia commented on June 8, 2024

Great point.

Instead of using DOM.Node.Node, I would prefer to parametize Pux.Html.Events types (MouseEvent, etc.). Instead of { target :: { value :: String } } it would be type MouseEvent a b = { target :: a, currentTarget :: b }.

Using it would like look:

module Counter where

import Prelude ((+), (-), const, show)
import Pux.Html (Html, div, span, button, text)
import Pux.Html.Events (MouseEvent, onClick)
import DOM.HTML.Types (HTMLElement)

data Action = Increment (MouseEvent HTMLElement HTMLElement) | Decrement

type State = Int

update :: Action -> State -> State
update (Increment ev) count = count + 1
update Decrement count = count - 1

view :: State -> Html Action
view count =
  div
    []
    [ button [ onClick Increment ] [ text "Increment" ]
    , span [] [ text (show count) ]
    , button [ onClick (const Decrement) ] [ text "Decrement" ]
    ]

What does everyone think about that? Other ideas?

from purescript-pux.

dkoontz avatar dkoontz commented on June 8, 2024

Is the parameterization so that you can substitute in any type that you want that matches the structure of the JS object from whatever DOM libraries there might be?

from purescript-pux.

alexmingoia avatar alexmingoia commented on June 8, 2024

Yes, exactly.

from purescript-pux.

srid avatar srid commented on June 8, 2024

Give that #80 is a duplicate of this am I correct in understanding that purescript-pux has no way of invoking an onClick handler while passing the target element being clicked?

All examples of purescript-pux I have seen so far make use of const to purposefully ignore the handler argument.

I wonder if anyone using purescript-pux for substantial projects have come across this bug, and have found a workaround? In my case I'm writing a board game where it is imperative know which of the cell was clicked ... and I am unable to do this in Pux's onClick handler.

from purescript-pux.

charleso avatar charleso commented on June 8, 2024

#81

from purescript-pux.

kozak avatar kozak commented on June 8, 2024

@HappyAndHarmless If you don't actually need the dom element, then maybe you could store the cells as a List of tuples List (CellID, CellState) and wrap the Clicked action of a Cell in an CellClicked CellId CellState action in the parent component, this way you could have the ID in the action handler without reading it from the DOM (if thats ok).

If thats the case, have a look at the list of counters examples (https://github.com/debois/elm-parts/blob/master/examples/2-counter-list.elm) or the pair of counters example here: https://github.com/alexmingoia/purescript-pux/blob/master/examples/pair-of-counters/App.purs

from purescript-pux.

srid avatar srid commented on June 8, 2024

@kozak - Ah, yes. That's a better way too.

from purescript-pux.

alexmingoia avatar alexmingoia commented on June 8, 2024

The Pux 8 release uses raw DOM events and the event type from purescript-dom. You can do anything you like with the raw DOM events now, and Pux provides a convenience function targetValue for grabbing .currentTarget.value.

from purescript-pux.

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.