Skip to content
This repository has been archived by the owner. It is now read-only.

syntax refactor #477

Open
wants to merge 4 commits into
base: master
from
Open

syntax refactor #477

wants to merge 4 commits into from

Conversation

@wuliupo
Copy link
Contributor

@wuliupo wuliupo commented Jul 20, 2016

Only syntax refactor,

  1. remove unused return null;
  2. a in b write in b.a will more clear;
  3. wrappers only have one property helper;
  4. _restore and _destroy were simplified as delete item.sortable.
@wuliupo wuliupo force-pushed the wuliupo:master branch from 9a72482 to b68ae26 Jul 20, 2016
@coveralls
Copy link

@coveralls coveralls commented Jul 20, 2016

Coverage Status

Coverage decreased (-0.6%) to 99.383% when pulling b68ae26 on wuliupo:master into 4bb4493 on angular-ui:master.

@@ -20,119 +20,114 @@ angular.module('ui.sortable', [])
uiSortable: '='
},
link: function(scope, element, attrs, ngModel) {
'use strict';

This comment has been minimized.

@thgreasi

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.

This comment has been minimized.

@wuliupo

wuliupo Jul 20, 2016
Author Contributor

Okay, I remove this line! Thanks!

@wuliupo wuliupo force-pushed the wuliupo:master branch from b68ae26 to 8e728b4 Jul 20, 2016
@coveralls
Copy link

@coveralls coveralls commented Jul 20, 2016

Coverage Status

Coverage decreased (-0.6%) to 99.383% when pulling 8e728b4 on wuliupo:master into 4bb4493 on angular-ui:master.


// 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]) {

This comment has been minimized.

@thgreasi

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()) &&

This comment has been minimized.

@thgreasi

thgreasi Jul 20, 2016
Member

Hmmm we also care about zero (0) dropindex.

}
optsDiff[key] = value;
opts[key] = value;
opts[key] = optsDiff[key] = patchSortableOption(key, value);

This comment has been minimized.

@thgreasi

thgreasi Jul 20, 2016
Member

I don't think that this is equivalent since we care whether there actually existed diffs or not.

This comment has been minimized.

@thgreasi

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]);

This comment has been minimized.

@thgreasi

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') {

This comment has been minimized.

@thgreasi

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();

This comment has been minimized.

@thgreasi

thgreasi Jul 20, 2016
Member

Where this one came form?

@thgreasi
Copy link
Member

@thgreasi thgreasi commented Jul 20, 2016

Please don't create a hure diff. Try not moving methods until the initial refactor gets reviewed.
Keep in mind that targeting the absolute min number of code lines can hurt the debug-ability of the code. Also refactoring chained method invocations to be in the same line can hurt the readability of the code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.