Is PureScript nice to use again? Tried it a year or two ago and it relied heavily on Bower and I had a hard time getting anything to work on Windows - lots of Bower errors and such. I tried it a few years ago and got it to work, but in that case getting Halogen to compile the most basic app just stuck the compiler into a freeze for minutes, so I gave up. But I am not shitting on PureScript, it looks like a fantastic…
I'm also wondering the same thing, after the whole Elm meltdown I've been looking for something similar to learn on the side.
How to write PureScript react components to replace JavaScript
21–30 of 74 posts
Re: How to write PureScript react components to replace JavaScript
#22Looking at the examples, the code seems to function the same so it's not obvious what problem is being solved that warrants teaching a whole dev team a new language.
In my experience, the vast majority of React app bugs are 1) state management, or 2) asynchronousisty. How does PureScript help to prevent those two classes of bugs?
Re: How to write PureScript react components to replace JavaScript
#23Re: How to write PureScript react components to replace JavaScript
#24This is the corresponding code written in React using hooks: export const Counter = ({label, counterType, onClick}) => { const [counter, setCounter] = useState(0); return ( { counterType == "Increment" && setCounter(counter + 1); counterType == "Decrement" && setCounter(counter - 1); onClick && onClick(); }}> {label}: {counter} ); } I think the case for PureScript React would be more convincing if the code you ended…
mkCounter :: Effect (ReactComponent {})
mkCounter = do
component "Counter" \props -> React.do
counter /\ setCounter show counter ]
}
Your aesthetic / background may differ from mine, but I find the Purescript version easier to read.[1]: https://github.com/spicydonuts/purescript-react-basic-hooks
Re: How to write PureScript react components to replace JavaScript
#25This is the corresponding code written in React using hooks: export const Counter = ({label, counterType, onClick}) => { const [counter, setCounter] = useState(0); return ( { counterType == "Increment" && setCounter(counter + 1); counterType == "Decrement" && setCounter(counter - 1); onClick && onClick(); }}> {label}: {counter} ); } I think the case for PureScript React would be more convincing if the code you ended…
(defn Counter [{:keys [label counterType onClick]
:or {onClick (fn [])}}]
(let [count (r/atom 0)]
[:button
{:onClick #(do (swap! count (condp = counterType
:increment inc
:decrement dec))
(onClick))}
(str label ": " @count)])))Re: How to write PureScript react components to replace JavaScript
#26This is the corresponding code written in React using hooks: export const Counter = ({label, counterType, onClick}) => { const [counter, setCounter] = useState(0); return ( { counterType == "Increment" && setCounter(counter + 1); counterType == "Decrement" && setCounter(counter - 1); onClick && onClick(); }}> {label}: {counter} ); } I think the case for PureScript React would be more convincing if the code you ended…
I think the counter updates should use functional updates, since they depend on the current state. My understanding is that this can lead to a potential race condition, although I'm not 100% on the details.
setCounter(currentCounter => currentCounter + 1)
https://reactjs.org/docs/hooks-reference.html#functional-upd...Interestingly your code is similar to some the first code in the basic 'into to hooks' section of the docs. Perhaps it's not a huge issue? Maybe somebody else who knows a bit more about React internals can chime in.
Re: How to write PureScript react components to replace JavaScript
#27Earlier quoted context omitted.
I'm also wondering the same thing, after the whole Elm meltdown I've been looking for something similar to learn on the side.
Elm meltdown?
Re: How to write PureScript react components to replace JavaScript
#28Why would anyone write purescript when we have typescript?
Re: How to write PureScript react components to replace JavaScript
#29Is PureScript nice to use again? Tried it a year or two ago and it relied heavily on Bower and I had a hard time getting anything to work on Windows - lots of Bower errors and such. I tried it a few years ago and got it to work, but in that case getting Halogen to compile the most basic app just stuck the compiler into a freeze for minutes, so I gave up. But I am not shitting on PureScript, it looks like a fantastic…
I'm also wondering the same thing, after the whole Elm meltdown I've been looking for something similar to learn on the side.
Re: How to write PureScript react components to replace JavaScript
#30Is PureScript nice to use again? Tried it a year or two ago and it relied heavily on Bower and I had a hard time getting anything to work on Windows - lots of Bower errors and such. I tried it a few years ago and got it to work, but in that case getting Halogen to compile the most basic app just stuck the compiler into a freeze for minutes, so I gave up. But I am not shitting on PureScript, it looks like a fantastic…
spago init
spago install halogen
spago build
Halogen is now at v5 which has removed a lot of the complexity and type wierdness that was around in v4. Highly recommend giving it another spin!Can't speak for how well it works on Windows though. Perhaps someone elso out there knows?