From aaf292c538d266490cb58f55c07c523330d0ef3a Mon Sep 17 00:00:00 2001 From: Christian Lawson-Perfect Date: Mon, 13 Jun 2016 10:00:13 +0100 Subject: [PATCH] knockout: run deferred tasks early If `ko.options.deferUpdates = true`, then updates to the UI don't happen immediately when you modify the viewModel. For the sortable binding, this means that after removing a moved item, it doesn't recreate it at the new position. Calling `ko.tasks.runEarly` before re-inserting the item into the observableArray makes KO register the removal. This is the fix proposed by @adriaanmeuris in RubaXa/Sortable#712 --- knockout-sortable.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/knockout-sortable.js b/knockout-sortable.js index 2f98896..f46298e 100644 --- a/knockout-sortable.js +++ b/knockout-sortable.js @@ -157,6 +157,8 @@ // Force knockout to update from.valueHasMutated(); } + // Force deferred tasks to run now, registering the removal + ko.tasks.runEarly(); // Insert the item on its new position to().splice(newIndex, 0, itemVM); // Make sure to tell knockout that we've modified the actual array.