diegopamio / angular-sails-bind

An angular service to bind scope models to sailsjs models thru socket
MIT License
136 stars 25 forks source link

JSON objects #28

Open rmckeel opened 9 years ago

rmckeel commented 9 years ago

Using a Sails model "item" that specifies "runtimeData" as a JSON object, I have not been able to get this to work when runtimeData is already set to a value. For instance, given this data existent in the MongoDB data store:

$scope.items[0].runtimeData = { "currentVal": 1 };

The following does not trigger an update: $scope.items[0].runtimeData.currentVal = 2;

And this rarely / unreliably triggers an update: $scope.items[0].runtimeData = { "currentVal" : 2 };

But this always triggers: $scope.items[0].runtimeData = { "lastUpdate" : new Date().getTime(), "currentVal" : 2 };

It seems that a combination of changing the entire runtimeData object AND including a value is what is causing the update to be performed properly. All bindings at the root level ($scope.items[0].customVal = "5") work great at mirroring back to the database.

Any ideas? I haven't dived into the code enough to know how to fix, and I am new to Angular.

Thanks!

Ryan

rmckeel commented 9 years ago

I think I've found a solution to this problem, at least for another layer of depth.

In 'addCollectionWatchersToSubitemsOf' function, change scope.$watchCollection(...) to scope.$watch(..., function (...) {}, true);

This is a more costly compare, but is vital for my app. I'm still working on identifying changes multiple layers down in the JSON tree.

diegopamio commented 9 years ago

Perhaps I could add a config setting to look for deep changes instead of collection changes. So if you want it and are willing to pay the performance price, you can.

Do you agree?