Live data from Hacker News

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

gwendall.github.io

41–50 of 62 posts

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

#41
post #31

I applied to the example here the first test I always make of any things like this: HTML injection. Result: failure. ☹

yup, my go to test name: \_(ʘ_ʘ)_/ "' caused it to show { "formData": { "name": "\\_(ʘ_ʘ)_/ \"'

Thanks! Fixed. I added a "way-html" attribute (boolean, false by default) that you can pass to your DOM elements.

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

#42
post #38
post #30

Earlier quoted context omitted.

If what you're doing is simple enough that "serialise the form, send to server, wait for response, do a full page reload" works for you, then no, you don't need two-way data binding, and in fact wouldn't have any use for it. You only need two-way data binding if you need your client-side code to respond to user input, which a truly basic form doesn't need to do. Of course, for a good user experience, you probably wan…

Im sceptical. You know why? You wrote all this text instead of giving me a real world example and said "look, this would be shitty without a 2-way-data-binding-library".

I listed multiple real world examples. Not sure what else you want.

Again, IF you have client side JS code, AND it needs to respond to user input, THEN you need code to trigger that such as two-way data binding, and event bus, dispatchers, whatever. If you do not have client side JS code, or it does not need to respond to user input, then you don't need any of that. Are you asking why you would have client side JS code at all, or...?

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

#43
post #42
post #38

Earlier quoted context omitted.

Im sceptical. You know why? You wrote all this text instead of giving me a real world example and said "look, this would be shitty without a 2-way-data-binding-library".

I listed multiple real world examples. Not sure what else you want. Again, IF you have client side JS code, AND it needs to respond to user input, THEN you need code to trigger that such as two-way data binding, and event bus, dispatchers, whatever. If you do not have client side JS code, or it does not need to respond to user input, then you don't need any of that. Are you asking why you would have client side JS co…

> I listed multiple real world examples.

I see no URLs in you text.

> THEN you need code to trigger that

I didnt't say you never need js code that reacts to input. I said: does anybody have real world examples where this type of library is useful?

Because most of the time I get along well with sending input to the server. And in the few cases I needed js to deal with user input I got along nicely with simple event handlers.

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

#45
Maybe I'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()?)

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...

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

#46
post #45

Maybe I'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()?) 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…

Correct link for Mithril: http://lhorie.github.io/mithril/

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

#47
post #43
post #42

Earlier quoted context omitted.

I listed multiple real world examples. Not sure what else you want. Again, IF you have client side JS code, AND it needs to respond to user input, THEN you need code to trigger that such as two-way data binding, and event bus, dispatchers, whatever. If you do not have client side JS code, or it does not need to respond to user input, then you don't need any of that. Are you asking why you would have client side JS co…

> I listed multiple real world examples. I see no URLs in you text. > THEN you need code to trigger that I didnt't say you never need js code that reacts to input. I said: does anybody have real world examples where this type of library is useful? Because most of the time I get along well with sending input to the server. And in the few cases I needed js to deal with user input I got along nicely with simple event ha…

> I didn't say you never need js code that reacts to input.

Actually, you kinda did:

> Im always under the assumption that the old "post data to server, save it there" model still works best.

Whatever you were trying to say with that question, I don't think it was coming through. Anyhow, to answer your actual question:

> I wonder who benefits from this kind of library. You can react to user input with a simple keyup event.

Well, obviously. The use case for two-way data binding is every single place you would ever use a simple keyup event. The two approaches do the same thing in very similar ways; and a two-way data binding library is generally nothing more than some simple boilerplate over the plain event binding. For example, with Knockout you could put this in your HTML:

    
Or if you like jQuery you could put this:

    
And then in your JS you could put this:

    $('#field1').keypress(handler);
As far as reacting to user input, they do the exact same thing in the exact same way. The difference is that Knockout example has very slightly less typing, that it's (to my eyes) very slightly clearer what's going on when you look at the HTML.

There's a lot of ways to structure an app. Two-way data binding helps with one of the obvious ways; it's simple and (if you're sane about it), clear. Which is probably why it's a core part of Angular, Knockout, Ember, Mithril, Vue, Ractive, and a bunch more frameworks besides, and provided by popular plugins for Backbone and React.

TL;DR: People who want some boilerplate to hide a bunch of ugly event binding.

Edit: To be clear, two-way data binding is one of many ways of organising an app, and by no means the best way. But if your question is "why not just use some random event bindings", I'm not sure you understand the problem space.

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

#48
post #38
post #30

Earlier quoted context omitted.

If what you're doing is simple enough that "serialise the form, send to server, wait for response, do a full page reload" works for you, then no, you don't need two-way data binding, and in fact wouldn't have any use for it. You only need two-way data binding if you need your client-side code to respond to user input, which a truly basic form doesn't need to do. Of course, for a good user experience, you probably wan…

Im sceptical. You know why? You wrote all this text instead of giving me a real world example and said "look, this would be shitty without a 2-way-data-binding-library".

> 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.

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

#49
post #46
post #45

Maybe I'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()?) 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…

Correct link for Mithril: http://lhorie.github.io/mithril/

Yeah, sorry, I just fixed it :)

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

#50
post #11

That's the only javascript framework one needs. 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...

> That's the only javascript framework one needs.

Tank: "It's a single celled protein combined with synthetic aminos, vitamins, and minerals. Everything the body needs."

Post reply on HN