SteveSanderson/knockout.mapping — Issue #60: Calling ko.mapping.fromJS() inside a ko.computed cause endless loop
Author: greenlaw110
Created: 2012-03-07 01:15:08+00:00
State: open

Here is the source code:

```javascript
if (!ui.loadSubscriptions) ui.loadSubscriptions = ko.computed(function() {
var client = data.curClient();
if (!client.subscriptions) {
$.ajax({
url: '/data/client/subscriptions',
dataType: 'json',
async: false,
data: {id: client._id()},
success: function(subscriptions) {
// ! the following statement cause the entire function been
// evaluate again and the ajax call will be executed again
// and so forth the mapping call. It generates an endless
// loop
client.subscriptions = ko.mapping.fromJS(subscriptions);
},
error: function(jqXHR, textStatus, errorThrown) {
_.error("error load client subscriptions");
throw errorThrown;
}
});
}
});
```