TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

How to write PureScript react components to replace JavaScript

99 点作者 JacksonGariety将近 5 年前

13 条评论

chvid将近 5 年前
This is the corresponding code written in React using hooks:<p><pre><code> export const Counter = ({label, counterType, onClick}) =&gt; { const [counter, setCounter] = useState(0); return ( &lt;button onClick={() =&gt; { counterType == &quot;Increment&quot; &amp;&amp; setCounter(counter + 1); counterType == &quot;Decrement&quot; &amp;&amp; setCounter(counter - 1); onClick &amp;&amp; onClick(); }}&gt; {label}: {counter} &lt;&#x2F;button&gt; ); } </code></pre> I think the case for PureScript React would be more convincing if the code you ended up with was loosely as concise as the above.
评论 #23638545 未加载
评论 #23638528 未加载
评论 #23637776 未加载
评论 #23637300 未加载
评论 #23638658 未加载
评论 #23638200 未加载
评论 #23637295 未加载
评论 #23642161 未加载
评论 #23637710 未加载
evanrelf将近 5 年前
You can also use React Hooks in PureScript with purescript-react-basic-hooks[1].<p>Or for a more native PureScript approach to single-page web apps, check out purescript-halogen[2] and purescript-halogen-hooks[3] (created by the author of this article).<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;spicydonuts&#x2F;purescript-react-basic-hooks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;spicydonuts&#x2F;purescript-react-basic-hooks</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;purescript-halogen&#x2F;purescript-halogen" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;purescript-halogen&#x2F;purescript-halogen</a><p>[3]: <a href="https:&#x2F;&#x2F;github.com&#x2F;thomashoneyman&#x2F;purescript-halogen-hooks" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;thomashoneyman&#x2F;purescript-halogen-hooks</a>
quickthrower2将近 5 年前
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 way to develop JS apps, and I&#x27;d love to use it.
评论 #23638735 未加载
评论 #23637862 未加载
andrenth将近 5 年前
Not to hijack the thread, but I’ve recently learned that Purescript-Native has a Go target [1].<p>Does anyone have experience with this? How practical would it be to use this where one would otherwise use Go?<p>[1] <a href="https:&#x2F;&#x2F;discourse.purescript.org&#x2F;t&#x2F;purescript-native-can-now-target-golang&#x2F;878" rel="nofollow">https:&#x2F;&#x2F;discourse.purescript.org&#x2F;t&#x2F;purescript-native-can-now...</a>
azangru将近 5 年前
How is Purescript these days?<p>I haven&#x27;t heard many news from its ecosystem since Phil Freeman stepped down from its active development. Purescript by Example must be quite outdated by now? I know that Alex Kelley is still working on his set of tutorials &quot;Make the Leap from Javascript to Purescript&quot;[0]. Anything else interesting going on?<p>I feel like there was a lot of excitement about Purescript in around 2015-2016, but then it sort of died out?<p>0 - <a href="https:&#x2F;&#x2F;github.com&#x2F;adkelley&#x2F;javascript-to-purescript" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;adkelley&#x2F;javascript-to-purescript</a>
评论 #23641095 未加载
评论 #23640921 未加载
lightgreen将近 5 年前
&gt; JavaScript apps to PureScript &gt; Both companies have seen a dramatic drop in bugs in production.<p>I suspect if they migrated from JavaScript to TypeScript instead they would have seen the same dramatic drop in bugs, but also migrated much quicker and would be able to hire engineers easier, and development speed would have increased (because of much better tooling&#x2F;IDE&#x2F;interop).<p>I think PureScript is a very bright project, I even want to try it myself, but realistically, comparison to plain JavaScript is not the best benchmark.
oweqruiowe将近 5 年前
How do they connect child components to parts of the application state in PureScript? I&#x27;m looking for a mechanism like react-redux&#x27;s `connect` function. Something that eliminates the need to pass state through the root component down to everything else.
michaelcampbell将近 5 年前
I admire his CLI approach to things, but this just seems dogmatic:<p><pre><code> echo -e &quot;\noutput\n.psc*\n.purs*\.spago&quot; &gt;&gt; .gitignore </code></pre> Sure, ok, saying &quot;add these entries to your .gitignore&quot; is too pedestrian?
评论 #23642817 未加载
fristys将近 5 年前
Holy shit that syntax looks disgusting. No way Jose.
Osiris将近 5 年前
The article says that PureScript helped them reduce bugs but fails to give any examples of how PureScript prevented bugs.<p>Looking at the examples, the code seems to function the same so it&#x27;s not obvious what problem is being solved that warrants teaching a whole dev team a new language.<p>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?
评论 #23639191 未加载
BFatts将近 5 年前
Do we need another strongly typed language that compiles to JavaScript? If that&#x27;s so important, why don&#x27;t people use C&#x2F;C++ and compile that to WASM for best performance too? We&#x27;ve got TypeScript... is it necessary to have yet another language??
评论 #23642298 未加载
barbarbar将近 5 年前
It seems like a horrible idea to introduce this one off framework where ever you go. I feel sorry for the companies that has to carry the burden of the rewrite to something known. This should be used for a hobby at home.
edem将近 5 年前
Why would anyone write purescript when we have typescript?
评论 #23641300 未加载
评论 #23639454 未加载
评论 #23638725 未加载