Comments (8)
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.
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.
Yes, exactly.
from purescript-pux.
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.
from purescript-pux.
@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.
@kozak - Ah, yes. That's a better way too.
from purescript-pux.
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)
- Combinator for adding incremented key attribute HOT 1
- defaultValue prop HOT 1
- Todomvc example doesn't work with React (instead of preact) HOT 1
- Single element children props is not an array with preact HOT 2
- Add react component as property to another react component (Material-UI) HOT 3
- onKey* events should use KeyboardEvent in handlers HOT 2
- Real world examples HOT 2
- Rendering large numbers of elements exceeds maximum call depth HOT 2
- Page refresh on a route results in 404 page not found HOT 1
- Pux.Router can't parse Facebook and Google login redirect query parameter HOT 1
- Permission to submit benchmark HOT 4
- Needs Aff 4.0 upgrade
- Event fires faster than state update
- Memoize doesn't appreciably improve performance HOT 3
- Is Pux still being mantained? HOT 1
- Plans to update for Purescript 0.12? HOT 5
- Release version 13 on pursuit HOT 5
- Starter app includes outdated bower, fails to build
- Starter app fails to build with error "Module Data.Comparison imports itself"
- Website is broken
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from purescript-pux.