Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Persisting Objects #49

Closed
kouphax opened this issue Aug 30, 2011 · 1 comment
Closed

Problem Persisting Objects #49

kouphax opened this issue Aug 30, 2011 · 1 comment
Labels

Comments

@kouphax
Copy link

kouphax commented Aug 30, 2011

The following bit of code extends your people example and attempts to add a new person by using $$(person) to extend the object and create new instances of the object. It seems I need to call persist each time or I get the error below. Either I am doing wrong (most likely) or there is a bug in the $$ method?

Error

Uncaught TypeError: Cannot read property 'adapter' of undefined
    agility.fn.persist.save
    e.extend.proxy.gjquery.js:16
    $$.controller.click #add:53317/:51
    e.extend.proxy.gjquery.js:16
    Mjquery.js:16
    f.event.handlejquery.js:17
    f.event.add.i.handle.k

Code

(function(){
    var person = $$({}, '<li data-bind="name"/>').persist($$.adapter.restful, {collection:'people'});

    var people = $$({
        model: {},
        view: {
        format: 
            '<div>\
            <span>Loading ...</span>\
            <button id="load">Load people</button><br/><br/>\
            <button id="add">Add Person</button><br/><br/>\
            People: <ul/>\
            </div>',
        style:
            '& {position:relative}\
            & span {position:absolute; top:0; right:0; padding:3px 6px; background:red; color:white; display:none; }'
        }, 
        controller: {
        'click #load': function(){
            this.empty();
            this.gather(person, 'append', 'ul');
        },
        'click #add': function(){
            var p = $$(person, {name: "New Person"}).persist($$.adapter.restful, {collection:'people'});                      
            p.save();
            this.append(p, "ul");
        },
        'persist:start': function(){
            this.view.$('span').show();
        },
        'persist:stop': function(){
            this.view.$('span').hide();
        }
        }
    }).persist();
    $$.document.append(people);
})();
@arturadib
Copy link
Owner

Thanks for reporting this. It should be fixed in upstream, so you can remove .persist() from:

var p = $$(person, {name: "New Person"}).persist($$.adapter.restful, {collection:'people'});

See also unit test specific for this at https://github.com/arturadib/agility/blob/master/test/public/persist.js#L61-68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants