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

Commit

Permalink
fix(polylines polygons attribute watching): updates not get set
Browse files Browse the repository at this point in the history
correctly fixes issue #1255
  • Loading branch information
nmccready committed Aug 17, 2015
1 parent aca29aa commit 4274d5a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 58 deletions.
30 changes: 16 additions & 14 deletions dist/angular-google-maps.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,18 +1449,17 @@ Nicholas McCready - https://twitter.com/nmccready
};

ModelKey.prototype.setChildScope = function(keys, childScope, model) {
_.each(keys, (function(_this) {
return function(name) {
var isScopeObj, newValue;
isScopeObj = _this.scopeOrModelVal(name, childScope, model, true);
if ((isScopeObj != null ? isScopeObj.value : void 0) != null) {
newValue = isScopeObj.value;
if (newValue !== childScope[name]) {
return childScope[name] = newValue;
}
var isScopeObj, key, name, newValue;
for (key in keys) {
name = keys[key];
isScopeObj = this.scopeOrModelVal(name, childScope, model, true);
if ((isScopeObj != null ? isScopeObj.value : void 0) != null) {
newValue = isScopeObj.value;
if (newValue !== childScope[name]) {
childScope[name] = newValue;
}
};
})(this));
}
}
return childScope.model = model;
};

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

BasePolysParentModel.prototype.watchModels = function(scope) {
return scope.$watchCollection('models', (function(_this) {
return scope.$watch('models', (function(_this) {
return function(newValue, oldValue) {
if (newValue !== oldValue) {
if (_this.doINeedToWipe(newValue) || scope.doRebuildAll) {
Expand All @@ -3974,7 +3973,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
}
}
};
})(this));
})(this), true);
};

BasePolysParentModel.prototype.doINeedToWipe = function(newValue) {
Expand Down Expand Up @@ -4102,7 +4101,10 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
}).then(function(state) {
payload = state;
if (payload.updates.length) {
$log.info("polygons updates: " + payload.updates.length + " will be missed");
_async.each(payload.updates, function(obj) {
_.extend(obj.child.scope, obj.model);
return obj.child.model = obj.model;
});
}
return _async.each(payload.removals, function(child) {
if (child != null) {
Expand Down
30 changes: 16 additions & 14 deletions dist/angular-google-maps_dev_mapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -1449,18 +1449,17 @@ Nicholas McCready - https://twitter.com/nmccready
};

ModelKey.prototype.setChildScope = function(keys, childScope, model) {
_.each(keys, (function(_this) {
return function(name) {
var isScopeObj, newValue;
isScopeObj = _this.scopeOrModelVal(name, childScope, model, true);
if ((isScopeObj != null ? isScopeObj.value : void 0) != null) {
newValue = isScopeObj.value;
if (newValue !== childScope[name]) {
return childScope[name] = newValue;
}
var isScopeObj, key, name, newValue;
for (key in keys) {
name = keys[key];
isScopeObj = this.scopeOrModelVal(name, childScope, model, true);
if ((isScopeObj != null ? isScopeObj.value : void 0) != null) {
newValue = isScopeObj.value;
if (newValue !== childScope[name]) {
childScope[name] = newValue;
}
};
})(this));
}
}
return childScope.model = model;
};

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

BasePolysParentModel.prototype.watchModels = function(scope) {
return scope.$watchCollection('models', (function(_this) {
return scope.$watch('models', (function(_this) {
return function(newValue, oldValue) {
if (newValue !== oldValue) {
if (_this.doINeedToWipe(newValue) || scope.doRebuildAll) {
Expand All @@ -3974,7 +3973,7 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
}
}
};
})(this));
})(this), true);
};

BasePolysParentModel.prototype.doINeedToWipe = function(newValue) {
Expand Down Expand Up @@ -4102,7 +4101,10 @@ Original idea from: http://stackoverflow.com/questions/22758950/google-map-drawi
}).then(function(state) {
payload = state;
if (payload.updates.length) {
$log.info("polygons updates: " + payload.updates.length + " will be missed");
_async.each(payload.updates, function(obj) {
_.extend(obj.child.scope, obj.model);
return obj.child.model = obj.model;
});
}
return _async.each(payload.removals, function(child) {
if (child != null) {
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-google-maps_dev_mapped.js.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ angular.module('uiGmapgoogle-maps.directives.api.models.parent')
@firstTime = true
@$log.info @

#@watchOurScope(scope)
# @watchOurScope(scope)
@createChildScopes()

#watch this scope(Parent to all Models), these updates reflect expression / Key changes
#thus they need to be pushed to all the children models so that they are bound to the correct objects / keys
# watch: (scope, name, nameKey) =>
# scope.$watch name, (newValue, oldValue) =>
# if (newValue != oldValue)
# maybeCanceled = null
# @[nameKey] = if _.isFunction newValue then newValue() else newValue
#
# _async.promiseLock @, uiGmapPromise.promiseTypes.update, "watch #{name} #{nameKey}"
# , ((canceledMsg) -> maybeCanceled = canceledMsg)
# , =>
# _async.each @plurals.values(), (model) =>
# model.scope[name] = if @[nameKey] == 'self' then model else model[@[nameKey]]
# maybeCanceled
# , _async.chunkSizeFrom scope.chunk

# watch: (scope, name, nameKey) =>
# scope.$watch name, (newValue, oldValue) =>
# if (newValue != oldValue)
# maybeCanceled = null
# @[nameKey] = if _.isFunction newValue then newValue() else newValue
#
# _async.promiseLock @, uiGmapPromise.promiseTypes.update, "watch #{name} #{nameKey}"
# , ((canceledMsg) -> maybeCanceled = canceledMsg)
# , =>
# _async.each @plurals.values(), (model) =>
# model.scope[name] = if @[nameKey] == 'self' then model else model[@[nameKey]]
# maybeCanceled
# , _async.chunkSizeFrom scope.chunk

watchModels: (scope) =>
scope.$watchCollection 'models', (newValue, oldValue) =>
scope.$watch 'models', (newValue, oldValue) =>
unless newValue == oldValue
if @doINeedToWipe(newValue) or scope.doRebuildAll
@rebuildAll(scope, true, true)
else
@createChildScopes(false)
, true

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

# watchOurScope: (scope) =>
# canCall = (maybeCall) ->
# return false unless _.isFunction(maybeCall)
# hasZeroArgs = !maybeCall.length
# hasZeroArgs
#
# _.each IPoly.scopeKeys, (name) =>
# nameKey = name + 'Key'
# @[nameKey] = if canCall(scope[name]) then scope[name]() else scope[name]
# @watch(scope, name, nameKey)
# watchOurScope: (scope) =>
# canCall = (maybeCall) ->
# return false unless _.isFunction(maybeCall)
# hasZeroArgs = !maybeCall.length
# hasZeroArgs
#
# _.each IPoly.scopeKeys, (name) =>
# nameKey = name + 'Key'
# @[nameKey] = if canCall(scope[name]) then scope[name]() else scope[name]
# @watch(scope, name, nameKey)

createChildScopes: (isCreatingFromScratch = true) =>
if angular.isUndefined(@scope.models)
Expand Down Expand Up @@ -136,8 +136,9 @@ angular.module('uiGmapgoogle-maps.directives.api.models.parent')
.then (state) =>
payload = state
if(payload.updates.length)
#TODO: not supporting updates yet
$log.info("polygons updates: #{payload.updates.length} will be missed")
_async.each payload.updates, (obj) =>
_.extend obj.child.scope, obj.model
obj.child.model = obj.model
_async.each payload.removals, (child) =>
if child?
child.destroy()
Expand Down
2 changes: 1 addition & 1 deletion src/coffee/directives/api/utils/model-key.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ angular.module('uiGmapgoogle-maps.directives.api.utils')


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

0 comments on commit 4274d5a

Please sign in to comment.