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

Re : Maximum call stack size exceeded on model destroy

$
0
0
Here is a breaking test case:
  1. test("Max Callstack Exceeded", function() {
        
        Policy = can.Model({
            id: 'name',
            attributes: {
                cacheDetails: 'Cache.model'
            },
            findAll: "GET /policies",
            destroy: "DELETE /policies/{id}"
        }, {});
        
        Cache = can.Model({
            id: 'name',
            attributes: {
                dataVolumes: 'Volume.models'
            }
        }, {});
        
        Volume = can.Model({
            id: 'name',
            attributes: {
                cacheDetails: 'Cache.model'
            },
            findOne: "GET /volumes/{id}",
            destroy: "DELETE /volumes/{id}"
        }, {
            getName: function() {}
        });
        
        var VOLUME = {
            "name": "Water",
            "cacheDetails": {
                "name": "Cache 0"
            }
        };
        
        var POLICIES = [
            {
                "name": "S3 cached",
                "cacheDetails": {            
                    "name": "Cache 0",
                    "dataVolumes": [
                        {
                            "name": "S3 volume",
                        },
                        {
                            "name": "Water",
                        }
                    ]
                },
                "volumes": [
                    {
                        "name": "S3 volume"
                    },
                    {
                        "name": "Water"
                    }
                ]
            }
        ];
        
        can.fixture('GET /policies', function() { return POLICIES; });
        can.fixture('GET /volumes/{id}', function() { return VOLUME; });
        can.fixture('DELETE /volumes/{id}', function() { return 1; });

        can.view.ejs("ejs","name: <%= v.attr('name') %>")
        
        var self = this;
        stop();
        Volume.findOne({id: 'Water'}).then(function(v) {
            console.dir(v);
            window.v = 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