162 points · by ges · 12y ago · 60 comments
What about dates? And data parsing/formatting in general?
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.
If you want to compare w/ Knockout/Angular/etc then there's even more stuff that could be considered as "missing" (e.g. condiditionals, partials/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 "lightweight".
My own framework Mithril ( http://lhorie.github.io/mithril ) for example is ~5kb gzipped, has no dependencies, and allows you to do quite a bit more in terms of templating and data binding.
Incidentally, I wrote a article a while back about how two-way binding isn't even always the best answer to your questions, and that there are often better ways to update javascript data from forms: http://lhorie.github.io/mithril-blog/asymmetrical-data-bindi...
http://jsperf.com/angular-vs-knockout-vs-ember/351
For me personally I am loving VueJS right now.
\_(ʘ_ʘ)_/ "'<!--/*༼ つ ◕_◕ ༽つ
caused it to show
{ "formData": { "name": "\\_(ʘ_ʘ)_/ \"'
<!
will show:
{ "formData": { "name": "
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.
In Spyne terms, that's "serializing a model instance using the HtmlForm protocol". 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 http://spyne.io to get a better feel about how it works.
One could even write a Spyne protocol that renders a given model instance to way.js code.
Help is welcome!
[1]: https://github.com/plq/neurons/blob/test_output/html/test_si...
[2]: https://github.com/plq/neurons/blob/fccab8fee4c1795f65ac3f9b...
[3]: http://spyne.io
You'll even be able to pass templates down a certain object hierarchy, but that's further down the pipeline.
Actually I've been wanting to write something like that for a long time but didn't get around to it. Nice to see someone else did exactly what I wanted...
Im always under the assumption that the old "post data to server, save it there" model still works best. Am I missing something?
Of course, for a good user experience, you probably want to do client-side validation of the form; while you can do that a bunch of ways one of the easier ways (from a developer's point of view) is two-way data binding, and I'm using it on a few contact forms, signup forms, file upload forms, etc., scattered around the web for just that purpose.
And if you're doing something more complicated, then you probably want your client side code to respond to user input. If you're using ANY client-side MVC, or if you're getting real time updates from a server (via websockets or whatever), or if you're basically doing any sort of "app" style functionality in the client, you'll probably need two way data binding or its functional equivalent. I've written a big CRM webapp that uses two-way data binding extensively; the old "every click is a full HTTP round trip" model would deliver a shockingly bad user experience.
That being said, two-way data binding isn't the only way to implement rich client-side functionality, it's just one of the conceptually simplest ways of doing it. Backbone has two-way data binding plugins, but the "default" is to use events instead. Ditto for React. But something needs to tie your client side code to user input, and one of the simple "somethings" is two way data binding.
But again, if your app doesn't have any client side code, obviously you don't need anything to tie user input to the code you don't have. So if your app doesn't need any more client-side functionality than, eg, Hacker News has, then you have no need for two-way data binding (or, hell, any JS code at all). But if you want something a bit more interactive, then you need something.
(That being said, I still have no idea what makes this library better than any of the many popular, mature libraries that already exist. I've used Knockout quite a bit; it works well.)
Worth noting that, from what I can see, Salesforce largely uses the "every click is a full HTTP round trip" approach and it seems to be quite popular. NB I'm not saying that Salesforce has the best interface ever, just that old-fashioned web applications can still be pretty successful.
Using way.js the button can be updated immediately whenever you change one of its properties, without waiting for a server response.
And saving the data to localstorage is very useful when the user is spending a long time filling the form and then accidentally closes the browser / clicks BACK / etc. It's a bit like autosaving a draft version of the form.
Sure, one can think up use cases. But I never had one. Thats why I asked for real world examples where 2-way-binding libraries are used.
[0]: https://builtwith.angularjs.org/ [1]: http://emberjs.com/ember-users/ [2]: http://www.discourse.org/
Some people prefer to do things your way, but lots of us really do like this sort of data binding and find it to be very useful.
https://developer.mozilla.org/en-US/docs/Web/API/FormData
Weir thing is, the formData doesn't specify a working .toString(), so if you log it, it looks empty, and you can't see any of the values until you POST. Standards committees are wonderful.
Tank: "It's a single celled protein combined with synthetic aminos, vitamins, and minerals. Everything the body needs."
OT: After building a couple of large applications in Angular I'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?
But I do sometimes need databinding from view to model (when I want users to enter data, and it just fills in my object), and I sometimes want databinding from model to view (where my data is nicely displayed).
So rather than doing something fiddly and different for each way, it makes more sense to just have 2-way databinding in the first place.
And that then makes it easier for when I _do_ want 2-way databinding - for instance allowing users to enter a filter to narrow down a list.
Wouldn't it be enough to add a keydown event to the field?
Possibilities are endless and you're more likely to implement them when it is so painless.
That being said, could an implementation be done without jQuery? Probably. I'm sure the author is open to pull requests if you want to give it a go.
I'm using Angular's databinding and recently it felt as if it was just convenient enough to implement a nice-to-have feature that I might have postponed otherwise.
I'm also careful with adding too many dependencies for simple things. But since I've committed to learning and using Angular anyways, I don't mind the weight and like using what it has to offer.
Collaboration applications need it.
less dependencies would be an added bonus