Increasing read calls with computed observable

28 views
Skip to first unread message

m.bo...@gmail.com

unread,
Apr 23, 2013, 2:55:48 PM4/23/13
to knock...@googlegroups.com
Dear fellow KO lovers,

Maybe somebody can help me with the following problem.

I've created a computed observable with a custom read() and write() implementation. When I use this custom computed observable, the write() functions properly, but the read isn't (I think). When I change the value with the write() function, the read() is called afterwards 1 time. When I change the value for the second time, the read is called twice. Everytime the write is called, the read is called once more than the last time.

I've created a small sample: http://jsfiddle.net/q4KQM/

Hopefully somebody knows the reason.

Thanks in advance!

Greetings,
M. Boejax.

Michael Best

unread,
Apr 23, 2013, 11:30:57 PM4/23/13
to knock...@googlegroups.com, m.bo...@gmail.com
Each time you change the checkbox value, you're creating a new computed observable. The old one doesn't go away, though. That's why you get every increasing numbers of reads.

-- Michael

m.bo...@gmail.com

unread,
Apr 24, 2013, 1:58:57 AM4/24/13
to knock...@googlegroups.com, m.bo...@gmail.com
Hello Michael,

Thanks for your answer. How can I fix this behaviour?

Do I have to define the function outside of the VM with: var myComputedObservable = function() { .....} and assign it : self.attributeBooleanValue = myComputedObservable;


Or is "return ko.computed({" the problem within the observable. And I've to defined it elsewhere, then return the definition.

Or can I remove somehow the previous computed observable?

THanks in advance!

Greeting M. Boejax.

Op woensdag 24 april 2013 05:30:57 UTC+2 schreef Michael Best het volgende:

Dennis Evans

unread,
Apr 24, 2013, 2:00:12 PM4/24/13
to knock...@googlegroups.com, m.bo...@gmail.com
Not quite sure what you're trying to accomplish outside of changing the 'type' attribute of a password input field to 'hide/show' the password.
It seems like an overly engineered solution.  Would something like this work better for you?

m.bo...@gmail.com

unread,
Apr 24, 2013, 5:18:13 PM4/24/13
to knock...@googlegroups.com, m.bo...@gmail.com
Hello Dennis,

Thanks for your answer. I created a special simplifier version as an example, to make my problem clear. So yes, based on this example the solution is overengineered. But in my normal project I need this kind of solution.

Greetings,
M. Boejax.

Op woensdag 24 april 2013 20:00:12 UTC+2 schreef Dennis Evans het volgende:
Reply all
Reply to author
Forward
0 new messages