TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Reactive UIs with React and Bacon

75 pointsby nullobjectabout 11 years ago

11 comments

dizietabout 11 years ago
Maybe I am not getting it, but to me react.js seems like a bad way of wrapping your view html in javascript.<p>What can you do easier using react.js (and backbone) that you can&#x27;t already do using knockout and plain html or whatever markup you prefer?<p>To me, there is a reason to abstract javascript and similar logic outside the plain html -- however the workflow of including script sources inside html that in turn include html that gets rendered is backwards.
评论 #7613083 未加载
评论 #7613100 未加载
评论 #7613027 未加载
评论 #7613078 未加载
评论 #7613944 未加载
评论 #7613043 未加载
davedxabout 11 years ago
&quot;Perhaps this example is a little too contrived, but the real power of reactive streams becomes apparent when you want to do something more complex.&quot;<p>What is that something? This is indeed a recurrent problem with all these new tools and technologies: small examples that don&#x27;t reveal the issues you will have when your system starts to get larger and more complex.
skrebbelabout 11 years ago
My team has been using React full time since half January. What felt like a gamble initially, turned into mad love. I understand why people still use e.g. Angular, but only for the same reason as why people still use PHP: legacy. React is simply <i>that</i> much better. I hope its ideas will spawn many followers.<p>Our design&#x2F;css&#x2F;markup person loves it, because with JSX she can trivially write familiar HTML, and at the same time she&#x27;s highly encouraged to make little reusable building blocks (components, in React lingo).<p>The result is that our view codebase is remarkably well structured, even though very little of it has been touched by seasoned hardcore programmer types. React pulls us into this &quot;pit of success&quot; of locality, reusability and clarity.<p>I&#x27;ll braindump what we do, for those interested, just to share an alternative approach as the one listed in this blog. I&#x27;m not sure whether it&#x27;s better or worse - we&#x27;re probably doing some things in ways that could be better, so I&#x27;m very open to questions and critique, too.<p>Our frontend architecture is Model-View-Nothing. Our view is pure React components, with a root component called View which has, as its state, the current page and the model. We also have a thin &quot;proxy&quot; with a function for each backend API call, but it has no state so it&#x27;s not very interesting in terms of architecture.<p>The model is a simple hierarchy of classes. We use TypeScript for these classes, but it could&#x27;ve been CoffeeScript, ES6 or JS-hacked classes as well, no difference. Our root model class owns all other model objects, hierarchically.<p>A user action typically causes our model to want to extend or update itself. It does API requests to our backend for this. In the case of PUT&#x2F;POST&#x2F;DELETE, we update the local model first, and then asynchronously send it to the server - our data is such that we can assume that most of the time, the operation will succeed. This is great, because we can re-render the view before the server even acknowledges the operation&#x27;s success. This makes the app is <i>very</i> snappy.<p>We even do the same with GET requests: very often, we already have <i>some</i> of the data we&#x27;re getting (e.g. if you go to a user profile, you typically clicked a link with that user&#x27;s name and avatar on it). When it makes sense, we just show the page immediately with what data we have, and show a little loading animation for the rest. Again, this makes the application feel very responsive.<p>This works for us without any additional tools, because our model layer <i>somewhat</i> resembles the structure of the view. I suspect that this is quite common (e.g. if you&#x27;re displaying a list of tweets by a user, you probably have a &quot;root -&gt; user -&gt; list-of-tweets&quot; structure both in the model and the view). It allows us to pass only the model data to a React component that it needs, making our React components very slim and reusable.<p>In effect, our model layer is one big client-side cache. The methods on the model deal with synchronizing this cache, and the view just re-renders whenever the model tells it to. Another benefit is that if users navigate to pages they&#x27;ve seen recently, we still have all the data, and can show it right away (and refresh it in the background).<p>All of this works great on mobile too. Especially when viewing a page you saw before (e.g. by hitting &quot;back&quot;), the difference is enormous: many mobile browsers cache very little history (at least my Chrome doesn&#x27;t do it much), but for our page, it&#x27;s instantly there.<p>We would&#x27;ve gone for this dynamic no matter what, because we want to make a web app that feels like a native app. Nevertheless, I believe that React allowed us to do it with amazing simplicity and effectiveness. Other tools, such as Spine[0] encourage the same asynchronous dynamic, but I believe that without React, we would&#x27;ve spent a lot more time fighting with state, asynch timing issues, and all that.<p>[0] <a href="http://spinejs.com/" rel="nofollow">http:&#x2F;&#x2F;spinejs.com&#x2F;</a>
评论 #7613411 未加载
评论 #7613234 未加载
评论 #7613292 未加载
评论 #7613181 未加载
评论 #7613405 未加载
dangoorabout 11 years ago
The use of setState in React strikes me as a code smell. React has two ways to provide state for components: props and state. I prefer using React in a more functional style: your model is managed separate from the view and updates are handled just by re-rendering the view from the top (which React handles efficiently).<p>In other words: I haven&#x27;t really seen a need for a library like Bacon when using React, because React provides a means for generating a view without &quot;wiring it up&quot; as you do in a typical reactive app. You just regenerate the view whenever an action is taken that might have changed the model.
评论 #7613569 未加载
dreamdu5tabout 11 years ago
Am I the only one frustrated by the seeming lack of communication and mindshare between devs working on React and those working on Web Components (polymer.js).<p>There&#x27;s so much overlap yet I can&#x27;t find a detailed comparison or discussion of the two directions. The mailing list discussions I&#x27;ve found the devs seem very dismissive of each others projects.
Kequcabout 11 years ago
All of this complex front end framework stuff I really don&#x27;t see that it is necessary. You can write basically the most important part of the framework into a very small coffeescript file.<p><a href="https://gist.github.com/Kequc/11083050" rel="nofollow">https:&#x2F;&#x2F;gist.github.com&#x2F;Kequc&#x2F;11083050</a><p>Then your class:<p><pre><code> class MyApp.Cat constructor: (data) -&gt; @element = $(&#x27;&lt;div class=&quot;cat&quot;&gt;&lt;&#x2F;div&gt;&#x27;) @update = new MyApp.Update @, name: (v) =&gt; @element.text v color: (v) =&gt; @element.css backgroundColor: v @update.all data new MyApp.Cat name: &quot;Gary&quot; color: &quot;#FF00FF&quot;</code></pre>
评论 #7613349 未加载
评论 #7613308 未加载
ehutch79about 11 years ago
Are you required to mix coffeescript and plain javascript like that?<p>What&#x27;s the advantages to writing half your app in js and half in coffee script?<p>at least it isn&#x27;t half coffeescript half typescript this time.
lightbladeabout 11 years ago
A lot of this is over kill. FRP has a lot of complexity overhead before things get easier. For task like simple data binding as shown by author, your regular data binding library (angular, knockout) is enough. Doing the same with Bacon only makes it more complex.<p>FRP only starts to excel when you need to weave multiple signal sources together. Examples includes key combination for certain hot key. Or signal switching when implementing drag and drop.
jbejaabout 11 years ago
I love how Reactjs is getting more and more popular, i was yearning for something of quality to reach the top in the js world this days, and React seems like a very good competitor. And what i like most of it, is as simple as jQuery.
susi22about 11 years ago
There is also a todomvc with undo using baconjs. It&#x27;s pretty neat when you can use Bacon model:<p><a href="https://github.com/hura/todomvc-react-baconjs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;hura&#x2F;todomvc-react-baconjs</a>
j_sabout 11 years ago
Thanks to so many sharing their experience here.<p>I am considering using React but am stuck supporting IE7(!). Can anyone share their practical experience using React with clunky browsers?
评论 #7614116 未加载