Skip to content

Commit ccb3640

Browse files
committed
Removed redundant code and added comment.
1 parent 8bdcf28 commit ccb3640

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/directives/array.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
1818
require: '?ngModel',
1919
link: function(scope, element, attrs, ngModel) {
2020
var formDefCache = {};
21-
var arr_change_watcher = false;
22-
21+
2322
// Watch for the form definition and then rewrite it.
2423
// It's the (first) array part of the key, '[]' that needs a number
2524
// corresponding to an index of the form.
2625
var once = scope.$watch(attrs.sfArray, function(form) {
27-
26+
2827
// An array model always needs a key so we know what part of the model
2928
// to look at. This makes us a bit incompatible with JSON Form, on the
3029
// other hand it enables two way binding.
3130
var list = sfSelect(form.key, scope.model);
32-
33-
// Stop a previous watcher
34-
if (arr_change_watcher) arr_change_watcher();
35-
arr_change_watcher = scope.$watch('model' + sfPath.normalize(form.key), function (val) {
31+
32+
// We only modify the same array instance but someone might change the array from
33+
// the outside so let's watch for that. We use an ordinary watch since the only case
34+
// we're really interested in is if its a new instance.
35+
scope.$watch('model' + sfPath.normalize(form.key), function() {
3636
list = sfSelect(form.key, scope.model);
3737
scope.modelArray = list;
3838
});
39-
39+
4040
// Since ng-model happily creates objects in a deep path when setting a
4141
// a value but not arrays we need to create the array.
4242
if (angular.isUndefined(list)) {
@@ -56,7 +56,7 @@ angular.module('schemaForm').directive('sfArray', ['sfSelect', 'schemaForm', 'sf
5656
if (form.items.length > 1) {
5757
subForm = {
5858
type: 'section',
59-
items: form.items.map(function(item){
59+
items: form.items.map(function(item) {
6060
item.ngModelOptions = form.ngModelOptions;
6161
item.readonly = form.readonly;
6262
return item;

0 commit comments

Comments
 (0)