totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

how does data-jc-bind work? #644

Closed Jusys closed 6 years ago

Jusys commented 6 years ago

How does automatic two-way data binding work? I have such code:

<div data-jc="textbox" data-jc-path="forma.Name" data-jc-bind="">Name</div> <button onclick="window.forma.Name='kuku'">Ok</button> <script> window.forma = {}; window.forma.Name = 'labas'; </script>

On page loading textbox is assigned value 'labas', but when I click Ok - textbox value does not change. When I call MAIN.update() - only then value changes.

Is this a bug or I'm missing something?

3.0.0 jComponent v15

petersirka commented 6 years ago

Look here: https://jsfiddle.net/petersirka/r0kmhtvw/

BTW: please use Total.js messenger for future questions: https://messenger.totaljs.com or my channel https://messenger.totaljs.com/petersirka/

petersirka commented 6 years ago

I forgot to answer:

<button onclick="window.forma.Name='kuku'">Ok</button>
<button onclick="SET('forma.Name', 'kuku')">Ok</button>
Jusys commented 6 years ago

Dėkoju.

Jusys commented 6 years ago

P.S. I thought that there is some automatic cycle, that checks values, like in angular..

petersirka commented 6 years ago

It's because of performance, but you can use jComponent CREATE() (A simple wrapper for Proxy object):

https://jsfiddle.net/petersirka/r0kmhtvw/4/ It doesn't work in IE: https://caniuse.com/#search=proxy