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.

Show HN: Way.js – Simple, persistent, framework-agnostic two-way databinding

162 pointsby gesalmost 11 years ago

18 comments

lhoriealmost 11 years ago
Maybe I&#x27;m just missing something, but is there no way to deal with arrays? You know, like looping through data and displaying things for each of them? (also related: what about looping through Object.keys()?)<p>What about dates? And data parsing&#x2F;formatting in general?<p>Those are kind of important for a bi-directional bindings library. Remember that the Javascript data is usually the canonical data and the displayed data is derived from it, not the other way around.<p>If you want to compare w&#x2F; Knockout&#x2F;Angular&#x2F;etc then there&#x27;s even more stuff that could be considered as &quot;missing&quot; (e.g. condiditionals, partials&#x2F;components, how-do-i-use-select2-with-it, etc). One could argue those are out of scope for a lightweight library, but then again, I think this library has too many dependencies for something that advertises itself as &quot;lightweight&quot;.<p>My own framework Mithril ( <a href="http://lhorie.github.io/mithril" rel="nofollow">http:&#x2F;&#x2F;lhorie.github.io&#x2F;mithril</a> ) for example is ~5kb gzipped, has no dependencies, and allows you to do quite a bit more in terms of templating and data binding.<p>Incidentally, I wrote a article a while back about how two-way binding isn&#x27;t even always the best answer to your questions, and that there are often better ways to update javascript data from forms: <a href="http://lhorie.github.io/mithril-blog/asymmetrical-data-bindings.html" rel="nofollow">http:&#x2F;&#x2F;lhorie.github.io&#x2F;mithril-blog&#x2F;asymmetrical-data-bindi...</a>
评论 #8177517 未加载
sleepyheadalmost 11 years ago
Why use invalid &#x27;way-data&#x27;-attributes when there is data-attributes?
评论 #8177195 未加载
onion2kalmost 11 years ago
Looks very nice indeed. Especially like the low overhead. I&#x27;ve been using an alternative, Cortex[1], recently. It&#x27;s similar, but with a pubsub based eventing system so your updates don&#x27;t need to be broadcast to every component that uses the data model (e.g. you can subscribe callbacks to specific changes in the model). It works nicely with React.js. Worth a look if way.js isn&#x27;t quite enough.<p>[1] <a href="https://github.com/mquan/cortex" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;mquan&#x2F;cortex</a>
threeseedalmost 11 years ago
Might be worth benchmarking against the others:<p><a href="http://jsperf.com/angular-vs-knockout-vs-ember/351" rel="nofollow">http:&#x2F;&#x2F;jsperf.com&#x2F;angular-vs-knockout-vs-ember&#x2F;351</a><p>For me personally I am loving VueJS right now.
评论 #8177018 未加载
chrismorganalmost 11 years ago
I applied to the example here the first test I always make of any things like this: HTML injection. Result: failure. ☹
评论 #8177115 未加载
plqalmost 11 years ago
I&#x27;ve been working on something pretty similar, but on the server side. It&#x27;s called &#x27;Neurons&#x27;, and it&#x27;s a pre-alpha Python library. It&#x27;s built on Spyne[3], an RPC framework which is another side project of mine that I&#x27;ve been working on for ~4 years now.<p>The aim with neurons initially is to let you generate a html form (e.g. [1]) and related services from just a model definition and an instance of this model (e.g. [2]), making it a breeze to publish CRUD pages. It currently handles complex stuff like dates, times, arrays and nested objects just fine.<p>In Spyne terms, that&#x27;s &quot;serializing a model instance using the HtmlForm protocol&quot;. The same object definition can be used to for other protocols like json as well as for persisting data to a relational database (via SQLAlchemy). You can play with the code generator at <a href="http://spyne.io" rel="nofollow">http:&#x2F;&#x2F;spyne.io</a> to get a better feel about how it works.<p>One could even write a Spyne protocol that renders a given model instance to way.js code.<p>Help is welcome!<p>[1]: <a href="https://github.com/plq/neurons/blob/test_output/html/test_simple_array.html" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;plq&#x2F;neurons&#x2F;blob&#x2F;test_output&#x2F;html&#x2F;test_si...</a><p>[2]: <a href="https://github.com/plq/neurons/blob/fccab8fee4c1795f65ac3f9b20d79cb1e9279a3f/neurons/form/test/test_form.py#L193" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;plq&#x2F;neurons&#x2F;blob&#x2F;fccab8fee4c1795f65ac3f9b...</a><p>[3]: <a href="http://spyne.io" rel="nofollow">http:&#x2F;&#x2F;spyne.io</a>
评论 #8178230 未加载
isheneralmost 11 years ago
That&#x27;s the only javascript framework one needs.<p>Actually I&#x27;ve been wanting to write something like that for a long time but didn&#x27;t get around to it. Nice to see someone else did exactly what I wanted...
评论 #8176904 未加载
评论 #8177581 未加载
评论 #8176995 未加载
gesalmost 11 years ago
Github repo: <a href="https://github.com/gwendall/way.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;gwendall&#x2F;way.js</a>
评论 #8176713 未加载
matthewmacleodalmost 11 years ago
I would also suggest looking at Rivets (<a href="http://rivetsjs.com" rel="nofollow">http:&#x2F;&#x2F;rivetsjs.com</a>) which is my current go-to solution for this sort of thing.
mattdeslalmost 11 years ago
Polluting global scope and a hard dependency on jQuery.. :(
评论 #8201917 未加载
Kiroalmost 11 years ago
Looks very straight-forward. Good job!<p>OT: After building a couple of large applications in Angular I&#x27;ve come to realize that I seldom need two-way bindings. The school example where you enter something in an input box and it shows up somewhere else in real-time is not really used in the real world. Or is it? Why do we need two-way data binding?
评论 #8176844 未加载
评论 #8177053 未加载
评论 #8176830 未加载
评论 #8176792 未加载
Ronsenshialmost 11 years ago
Great job, i just wish it was at least no dependent on several other libraries including jQuery.
评论 #8176989 未加载
评论 #8201913 未加载
jesalgalmost 11 years ago
This is cool but in real world scenarios you need more functionality to make it useful. So far I&#x27;ve been using KnockoutJS where I don&#x27;t need full-blown MVC and can get away with MVVM.
danhanlyalmost 11 years ago
Is it me, or should the description read: &quot;This form is bound to the &#x27;formData&#x27; property&quot; instead of &quot;This form is binded to the &#x27;formData&#x27; property&quot;
评论 #8177014 未加载
rubiquityalmost 11 years ago
We&#x27;re still using HTML attributes, and in this case invalid HTML attributes, to add behavior via JavaScript? When are we going to learn :&#x2F;
nawitusalmost 11 years ago
How does Way.js detect changes made in JavaScript to the values? E.g. if you set a new property to the object, is it reflected in the DOM?
dodygalmost 11 years ago
How do you compare this with ractivejs.org?
评论 #8177167 未加载
antonwinteralmost 11 years ago
looks damn fine,<p>less dependencies would be an added bonus