rniemeyer / knockout-sortable

A Knockout.js binding to connect observableArrays with jQuery UI sortable functionality
MIT License
548 stars 128 forks source link

observableArray extended with deferred: true removes items from list #184

Open ksirmons opened 7 years ago

ksirmons commented 7 years ago

When observableArray is extended to be deferred like ko.observableArray([]).extend({ deferred: true }); some items disappear from GUI when dropped.

This is happening in knockout 3.4.2.

Found code in knockout-sortable where it checks for deferUpdates and runs ko.tasks.runEarly(); but this checks if all of knockout is being deferred, not a single observable array being extended to be deferred.

Changing the if statement if (ko.options && ko.options.deferUpdates) { ko.tasks.runEarly(); }

to

if ((ko.options && ko.options.deferUpdates) || (sourceParent && sourceParent._deferUpdates)) { ko.tasks.runEarly(); } fixes the issue for me.

Keith

mbest commented 7 years ago

Checking _deferUpdates will only work if using the debug version of Knockout. I'm not sure if there's a way to check in all cases.

ksirmons commented 7 years ago

Would it hurt to just run ko.tasks.runEarly(); every time, and not check for 'if deferUpdates'? if (typeof ko.tasks.runEarly === "function") { ko.tasks.runEarly(); }