angular-sails-bind icon indicating copy to clipboard operation
angular-sails-bind copied to clipboard

JSON objects

Open rmckeel opened this issue 11 years ago • 2 comments

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 avatar Jan 09 '15 21:01 rmckeel

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.

rmckeel avatar Jan 13 '15 19:01 rmckeel

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?

diegopamio avatar May 04 '15 14:05 diegopamio