Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
syntax refactor #477
syntax refactor #477
Conversation
@@ -20,119 +20,114 @@ angular.module('ui.sortable', []) | |||
uiSortable: '=' | |||
}, | |||
link: function(scope, element, attrs, ngModel) { | |||
'use strict'; |
thgreasi
Jul 20, 2016
•
Member
I'm totally in favor of 'use strict', but this might cause errors in some ASP.Net environments.
jQuery prior v3 also didn't use 'use strict' for exactly that reason.
|
||
// update changed options | ||
angular.forEach(newVal, function(value, key) { | ||
// if it's a custom option of the directive, | ||
// handle it approprietly | ||
if (key in directiveOpts) { | ||
if (directiveOpts[key]) { |
thgreasi
Jul 20, 2016
Member
That's not equivalent in case of directiveOpts members with falsy values.
@@ -381,7 +342,7 @@ angular.module('ui.sortable', []) | |||
} else { | |||
// if the item was not moved, then restore the elements | |||
// so that the ngRepeat's comment are correct. | |||
if ((!('dropindex' in ui.item.sortable) || ui.item.sortable.isCanceled()) && | |||
if ((!ui.item.sortable.dropindex || ui.item.sortable.isCanceled()) && |
} | ||
optsDiff[key] = value; | ||
opts[key] = value; | ||
opts[key] = optsDiff[key] = patchSortableOption(key, value); |
thgreasi
Jul 20, 2016
Member
I don't think that this is equivalent since we care whether there actually existed diffs or not.
thgreasi
Jul 20, 2016
Member
having a separate optsDiff = optsDiff || {};
line everywhere optsDiff
is used, would be more appropriate
} | ||
}); | ||
} | ||
opts[key] = optsDiff[key] = patchSortableOption(key, defaultOptions[key]); |
thgreasi
Jul 20, 2016
Member
There was some lazy laoding code here in order to avoid unnecessary object creations and (as a result) GC cycles.
} | ||
// wrap the callback | ||
value = combineCallbacks(callbacks[key], value); | ||
} else if (wrappers[key]) { | ||
value = wrappers[key](value); | ||
} else if ( key === 'helper' && typeof value === 'function') { |
thgreasi
Jul 20, 2016
Member
I preferred the more generic approach, since this would require less effort in case we need to wrap any other callback.
value = combineCallbacks(value, function (e, ui) { | ||
// call apply after stop | ||
scope.$apply(); | ||
ui.item.sortable._destroy(); |
Please don't create a hure diff. Try not moving methods until the initial refactor gets reviewed. |
Only syntax refactor,
return null
;a in b
write inb.a
will more clear;_restore
and_destroy
were simplified asdelete item.sortable
.