Skip to content
This repository was archived by the owner on Nov 30, 2018. It is now read-only.

Commit 4274d5a

Browse files
committed
fix(polylines polygons attribute watching): updates not get set
correctly fixes issue #1255
1 parent aca29aa commit 4274d5a

File tree

5 files changed

+63
-58
lines changed

5 files changed

+63
-58
lines changed

dist/angular-google-maps.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,18 +1449,17 @@ Nicholas McCready - https://twitter.com/nmccready
14491449
};
14501450

14511451
ModelKey.prototype.setChildScope = function(keys, childScope, model) {
1452-
_.each(keys, (function(_this) {
1453-
return function(name) {
1454-
var isScopeObj, newValue;
1455-
isScopeObj = _this.scopeOrModelVal(name, childScope, model, true);
1456-
if ((isScopeObj != null ? isScopeObj.value : void 0) != null) {
1457-
newValue = isScopeObj.value;
1458-
if (newValue !== childScope[name]) {
1459-
return childScope[name] = newValue;
1460-
}
1452+
var isScopeObj, key, name, newValue;
1453+
for (key in keys) {
1454+
name = keys[key];
1455+
isScopeObj = this.scopeOrModelVal(name, childScope, model, true);
1456+
if ((isScopeObj != null ? isScopeObj.value : void 0) != null) {
1457+
newValue = isScopeObj.value;
1458+
if (newValue !== childScope[name]) {
1459+
childScope[name] = newValue;
14611460
}
1462-
};
1463-
})(this));
1461+
}
1462+
}
14641463
return childScope.model = model;
14651464
};
14661465

@@ -3964,7 +3963,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
39643963
}
39653964

39663965
BasePolysParentModel.prototype.watchModels = function(scope) {
3967-
return scope.$watchCollection('models', (function(_this) {
3966+
return scope.$watch('models', (function(_this) {
39683967
return function(newValue, oldValue) {
39693968
if (newValue !== oldValue) {
39703969
if (_this.doINeedToWipe(newValue) || scope.doRebuildAll) {
@@ -3974,7 +3973,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
39743973
}
39753974
}
39763975
};
3977-
})(this));
3976+
})(this), true);
39783977
};
39793978

39803979
BasePolysParentModel.prototype.doINeedToWipe = function(newValue) {
@@ -4102,7 +4101,10 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
41024101
}).then(function(state) {
41034102
payload = state;
41044103
if (payload.updates.length) {
4105-
$log.info("polygons updates: " + payload.updates.length + " will be missed");
4104+
_async.each(payload.updates, function(obj) {
4105+
_.extend(obj.child.scope, obj.model);
4106+
return obj.child.model = obj.model;
4107+
});
41064108
}
41074109
return _async.each(payload.removals, function(child) {
41084110
if (child != null) {

dist/angular-google-maps_dev_mapped.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,18 +1449,17 @@ Nicholas McCready - https://twitter.com/nmccready
14491449
};
14501450

14511451
ModelKey.prototype.setChildScope = function(keys, childScope, model) {
1452-
_.each(keys, (function(_this) {
1453-
return function(name) {
1454-
var isScopeObj, newValue;
1455-
isScopeObj = _this.scopeOrModelVal(name, childScope, model, true);
1456-
if ((isScopeObj != null ? isScopeObj.value : void 0) != null) {
1457-
newValue = isScopeObj.value;
1458-
if (newValue !== childScope[name]) {
1459-
return childScope[name] = newValue;
1460-
}
1452+
var isScopeObj, key, name, newValue;
1453+
for (key in keys) {
1454+
name = keys[key];
1455+
isScopeObj = this.scopeOrModelVal(name, childScope, model, true);
1456+
if ((isScopeObj != null ? isScopeObj.value : void 0) != null) {
1457+
newValue = isScopeObj.value;
1458+
if (newValue !== childScope[name]) {
1459+
childScope[name] = newValue;
14611460
}
1462-
};
1463-
})(this));
1461+
}
1462+
}
14641463
return childScope.model = model;
14651464
};
14661465

@@ -3964,7 +3963,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
39643963
}
39653964

39663965
BasePolysParentModel.prototype.watchModels = function(scope) {
3967-
return scope.$watchCollection('models', (function(_this) {
3966+
return scope.$watch('models', (function(_this) {
39683967
return function(newValue, oldValue) {
39693968
if (newValue !== oldValue) {
39703969
if (_this.doINeedToWipe(newValue) || scope.doRebuildAll) {
@@ -3974,7 +3973,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
39743973
}
39753974
}
39763975
};
3977-
})(this));
3976+
})(this), true);
39783977
};
39793978

39803979
BasePolysParentModel.prototype.doINeedToWipe = function(newValue) {
@@ -4102,7 +4101,10 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
41024101
}).then(function(state) {
41034102
payload = state;
41044103
if (payload.updates.length) {
4105-
$log.info("polygons updates: " + payload.updates.length + " will be missed");
4104+
_async.each(payload.updates, function(obj) {
4105+
_.extend(obj.child.scope, obj.model);
4106+
return obj.child.model = obj.model;
4107+
});
41064108
}
41074109
return _async.each(payload.removals, function(child) {
41084110
if (child != null) {

dist/angular-google-maps_dev_mapped.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/coffee/directives/api/models/parent/base-polys-parent-model.coffee

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,33 @@ angular.module('uiGmapgoogle-maps.directives.api.models.parent')
2020
@firstTime = true
2121
@$log.info @
2222

23-
#@watchOurScope(scope)
23+
# @watchOurScope(scope)
2424
@createChildScopes()
2525

2626
#watch this scope(Parent to all Models), these updates reflect expression / Key changes
2727
#thus they need to be pushed to all the children models so that they are bound to the correct objects / keys
28-
# watch: (scope, name, nameKey) =>
29-
# scope.$watch name, (newValue, oldValue) =>
30-
# if (newValue != oldValue)
31-
# maybeCanceled = null
32-
# @[nameKey] = if _.isFunction newValue then newValue() else newValue
33-
#
34-
# _async.promiseLock @, uiGmapPromise.promiseTypes.update, "watch #{name} #{nameKey}"
35-
# , ((canceledMsg) -> maybeCanceled = canceledMsg)
36-
# , =>
37-
# _async.each @plurals.values(), (model) =>
38-
# model.scope[name] = if @[nameKey] == 'self' then model else model[@[nameKey]]
39-
# maybeCanceled
40-
# , _async.chunkSizeFrom scope.chunk
41-
28+
# watch: (scope, name, nameKey) =>
29+
# scope.$watch name, (newValue, oldValue) =>
30+
# if (newValue != oldValue)
31+
# maybeCanceled = null
32+
# @[nameKey] = if _.isFunction newValue then newValue() else newValue
33+
#
34+
# _async.promiseLock @, uiGmapPromise.promiseTypes.update, "watch #{name} #{nameKey}"
35+
# , ((canceledMsg) -> maybeCanceled = canceledMsg)
36+
# , =>
37+
# _async.each @plurals.values(), (model) =>
38+
# model.scope[name] = if @[nameKey] == 'self' then model else model[@[nameKey]]
39+
# maybeCanceled
40+
# , _async.chunkSizeFrom scope.chunk
4241

4342
watchModels: (scope) =>
44-
scope.$watchCollection 'models', (newValue, oldValue) =>
43+
scope.$watch 'models', (newValue, oldValue) =>
4544
unless newValue == oldValue
4645
if @doINeedToWipe(newValue) or scope.doRebuildAll
4746
@rebuildAll(scope, true, true)
4847
else
4948
@createChildScopes(false)
49+
, true
5050

5151
doINeedToWipe: (newValue) =>
5252
newValueIsEmpty = if newValue? then newValue.length == 0 else true
@@ -69,16 +69,16 @@ angular.module('uiGmapgoogle-maps.directives.api.models.parent')
6969
scope.$on '$destroy', =>
7070
@rebuildAll(scope, false, true)
7171

72-
# watchOurScope: (scope) =>
73-
# canCall = (maybeCall) ->
74-
# return false unless _.isFunction(maybeCall)
75-
# hasZeroArgs = !maybeCall.length
76-
# hasZeroArgs
77-
#
78-
# _.each IPoly.scopeKeys, (name) =>
79-
# nameKey = name + 'Key'
80-
# @[nameKey] = if canCall(scope[name]) then scope[name]() else scope[name]
81-
# @watch(scope, name, nameKey)
72+
# watchOurScope: (scope) =>
73+
# canCall = (maybeCall) ->
74+
# return false unless _.isFunction(maybeCall)
75+
# hasZeroArgs = !maybeCall.length
76+
# hasZeroArgs
77+
#
78+
# _.each IPoly.scopeKeys, (name) =>
79+
# nameKey = name + 'Key'
80+
# @[nameKey] = if canCall(scope[name]) then scope[name]() else scope[name]
81+
# @watch(scope, name, nameKey)
8282

8383
createChildScopes: (isCreatingFromScratch = true) =>
8484
if angular.isUndefined(@scope.models)
@@ -136,8 +136,9 @@ angular.module('uiGmapgoogle-maps.directives.api.models.parent')
136136
.then (state) =>
137137
payload = state
138138
if(payload.updates.length)
139-
#TODO: not supporting updates yet
140-
$log.info("polygons updates: #{payload.updates.length} will be missed")
139+
_async.each payload.updates, (obj) =>
140+
_.extend obj.child.scope, obj.model
141+
obj.child.model = obj.model
141142
_async.each payload.removals, (child) =>
142143
if child?
143144
child.destroy()

src/coffee/directives/api/utils/model-key.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ angular.module('uiGmapgoogle-maps.directives.api.utils')
114114

115115

116116
setChildScope: (keys, childScope, model) =>
117-
_.each keys, (name) =>
117+
for key, name of keys
118118
isScopeObj = @scopeOrModelVal name, childScope, model, true
119119
if isScopeObj?.value? #if we have something evaluated save to scope to not reevaluate on init
120120
newValue = isScopeObj.value

0 commit comments

Comments
 (0)