Comments (5)
Interesting.
The sortableList binding first deletes and and then re-inserts the moved item in the array. Normally this invokes two updates to the foreach binding, first deleting and then inserting an item. When using deferred updates, those two updates are combined, and although foreach still does a delete and insert, it may not be of the same item. For example, if we start with 1, 2, 3 and change it to 2, 1, 3, here's what happens normally:
- 1, 3 (delete 2)
- 2, 1, 3 (insert 2)
Here's what happens when you combine the updates:
- 2, 3 (delete 1)
- 2, 1, 3 (insert 1)
The end result should be the same, but because the sortableList binding has deleted the element for item 2, the new list just has 1 and 3.
There are two ways to fix this problem. The first is not have sortableList remove the element and let foreach do all the updates. In order for this to work, we have to make sure that foreach only sees the LI element without any text around it: http://jsfiddle.net/mbest/AZqJQ/17/
The second is the make sure that foreach gets two updates. For that we can use ko.processAllDeferredBindingUpdates()
: http://jsfiddle.net/mbest/AZqJQ/18/
from knockout-deferred-updates.
Obviously a lesson here is that sometimes you really don't want updates to be combined. Unfortunately, there's no way to know automatically when that's the case.
from knockout-deferred-updates.
Your second solution worked best (using ko.processAllDeferredBindingUpdates() ). The first solution still caused the problem at times.
Thanks so much!!!!
On Friday, March 2, 2012 at 6:24 PM, Michael Best wrote:
Obviously a lesson here is that sometimes you really don't want updates to be combined. Unfortunately, there's no way to know automatically when that's the case.
Reply to this email directly or view it on GitHub:
#2 (comment)
from knockout-deferred-updates.
Your second solution worked best (using ko.processAllDeferredBindingUpdates() ). The first solution still caused the problem at times.
I think the problem might be with the original implementation, because I found problems even with using processAllDeferredBindingUpdates. Here's the problem I found: Drag item one below item two (but don't drop it) and then put it back; drag item three before two (and don't drop it) and put it back; drag item one and put it after item two. Now the list are out of sync. This specific problem doesn't happen with my first solution, rev 17., but does happen with your original fiddle when I remove the deferred updates plugin.
Here's a version that uses processAllDeferredBindingUpdates and also changes the logic of the binding to one that should always work: http://jsfiddle.net/mbest/AZqJQ/20/
from knockout-deferred-updates.
Thanks! I just implemented the new fix. Itβs working great.
-Scott
On Sunday, March 4, 2012 at 7:20 PM, Michael Best wrote:
Your second solution worked best (using ko.processAllDeferredBindingUpdates() ). The first solution still caused the problem at times.
I think the problem might be with the original implementation, because I found problems even with using processAllDeferredBindingUpdates. Here's the problem I found: Drag item one below item two (but don't drop it) and then put it back; drag item three before two (and don't drop it) and put it back; drag item one and put it after item two. Now the list are out of sync. This specific problem doesn't happen with my first solution, rev 17., but does happen with your original fiddle when I remove the deferred updates plugin.
Here's a version that uses processAllDeferredBindingUpdates and also changes the logic of the binding to one that should always work: http://jsfiddle.net/mbest/AZqJQ/20/
Reply to this email directly or view it on GitHub:
#2 (comment)
from knockout-deferred-updates.
Related Issues (20)
- IE8 Compatibility - try...finally blocks HOT 2
- semver tags (for bower compatibility) HOT 2
- Doesn't support KO 3.0.0 HOT 1
- dependentObservable.notifySubscribers = undefined HOT 3
- Consider using postMessage rather than setTimeout HOT 1
- Experiencing lock-up (memory leak, +4MB/s, 30% CPU) when including this after knockout in chrome. HOT 17
- Browser CPU goes to 100% after including this js on my page HOT 14
- knockout-deferred-updates does not play nicely with Throttle in Safari IOS 7 HOT 7
- Doesn't support KO 3.1.0beta HOT 2
- Performance seems to be much worse than without deferred-updates HOT 1
- Performance issue... again
- knockout 3.2 HOT 3
- Knockout computed update notification sometimes not firing HOT 5
- Use `after` on update for bindings which are deferred together. HOT 3
- Knockout 3.3? HOT 2
- Breaks deferEvaluation computed bindings on IE10 with KO 3.1+ HOT 5
- Uncaught binding error prevents other bindings from running
- Getting TypeError: currentFrame.callback is not a function HOT 5
- Knockout 3.4 HOT 7
- newCallback used out of scope HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knockout-deferred-updates.