if binding not working instantly

115 views
Skip to first unread message

tomkom...@gmail.com

unread,
Mar 18, 2015, 5:24:45 AM3/18/15
to knock...@googlegroups.com
I have a following code, that is run in the menu partial view of my page.
<div  data-bind="if: Logined() && Messages().length > 0">
    <a href="@Url.Action("Notifications", "User")"><span class="glyphicon-message" data-bind="text: Messages().length"></span></a>
</div>
The thing is, it takes 0.1 - 0.5 seconds for knockout to "hide" it.
Does anyone know, how to fix this ? I thought about adding hidden="hidden", and then to bind visible instead of if, but that's not the viable option

Noirabys

unread,
Mar 18, 2015, 10:56:50 AM3/18/15
to knock...@googlegroups.com
i don't think its knockout which takes so long, what exacty is Logined and Messages ? 

Tom Komarnicki

unread,
Mar 18, 2015, 11:59:26 AM3/18/15
to knock...@googlegroups.com
logined is a bool value, and "messages" is the messages that user has received.
Both are being passed in the view model, so that's the issue with database/server.

середа, 18 березня 2015 р. 16:56:50 UTC+2 користувач Noirabys написав:

Ian Yates

unread,
Mar 22, 2015, 11:26:27 PM3/22/15
to knock...@googlegroups.com
Are either computed observables or are they both plain observables?

If one or both are computed observables then it might be worth putting a console.log at the start and finish of each one to see how often they're being evaluated due to changing dependencies.  Maybe it's many times?

Another approach to debugging would be to make your if binding redundant for the moment by making it
<div data-bind="if:  true && Logined() && Message().length > 0">

That ought to evaluate quickly due to short-circuit Boolean evaluation.  Try it with false instead of true.  Does the page still act sluggishly?  If so then you've got something else that's slowing down your browser and it's just that the evaluation of this if binding is a casualty.

You could also add a
<span data-bind="text: ko.toJSON( Logined() )"> </span> tag to your page.  Do the same for Message().length.  Do they update quickly?
Reply all
Reply to author
Forward
0 new messages