Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : Maximum call stack size exceeded on model destroy

$
0
0
Ok, so I cleaned it up "a little" (removed fixtures and globals) and I uncovered an interesting fact. When I got rid of the globals as in the example below, I do not see the error. But if you remove the "var" keyword from Volume and Policy, you will get the max callstack error.
  1. test("Max Callstack Exceeded", function() {
        
        var Policy = can.Model({
            id: 'name',
            attributes: {
                cacheDetails: 'Cache.model'
            },
            findAll: function() {
             var dfd = can.Deferred();
             setTimeout(function() {
             dfd.resolve([
            {
                "name": "S3 cached",
                "cacheDetails": {            
                    "name": "Cache 0",
                    "dataVolumes": [
                        {
                            "name": "S3 volume",
                        },
                        {
                            "name": "Water",
                        }
                    ]
                },
                "volumes": [
                    {
                        "name": "S3 volume"
                    },
                    {
                        "name": "Water"
                    }
                ]
            }
        ]);
             }, 100);
             return dfd;
            },
            destroy: "DELETE /policies/{id}"
        }, {});
        
        var Cache = can.Model({
            id: 'name',
            attributes: {
                dataVolumes: 'Volume.models'
            }
        }, {});
        
        var Volume = can.Model({
            id: 'name',
            attributes: {
                cacheDetails: 'Cache.model'
            },
            findOne: function() {
             var dfd = can.Deferred();
    setTimeout(function() {
    dfd.resolve({
            "name": "Water",
            "cacheDetails": {
                "name": "Cache 0"
            }
        });
    }, 100)
    return dfd;
            },
            destroy: function() {
             var dfd = can.Deferred();
    setTimeout(function() {
    dfd.resolve(true);
    }, 100)
    return dfd;
            }
        }, {
            getName: function() {}
        });

        can.view.ejs("ejs","name: <%= v.attr('name') %>")
        
        stop();
        Volume.findOne({id: 'Water'}).then(function(v) {
            
            // Comment this line out and no maximum call stack error
            can.$('#dummy').append(can.view('ejs', {
                v: v
            }))
            
            // Second call to Policy.findAll is what seems to trigger the issue
            // Comment this line out and no maximum call stack error
            Policy.findAll().then(function() {
             v.destroy().then(function() {
             start();
             equal(1,1, "We made it here so all good!");
             })
            });
        });
    });

Viewing all articles
Browse latest Browse all 3491

Trending Articles