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

Default serialize implementation (Fix #358) #365

Merged
merged 1 commit into from Sep 9, 2013
Merged

Default serialize implementation (Fix #358) #365

merged 1 commit into from Sep 9, 2013

Conversation

SBoudrias
Copy link
Collaborator

To continue the discussion over a suggested implementation and allow people to test it out!

On a side note, I got different behavior in Underscore between Node and the browser. In the browser, undefined template value were ignored as in node they throwed error.

@nicoburns
Copy link

Just thought I would contribute our default serialize function:

serialize: function() {
    if (this.model) {
        return this.model.toJSON();
    }
    else if(this.collection) {
        return {
            items: this.collection.toJSON(),
            hasItems: this.collection.length > 0
        };
    }
    else {
        return {};
    }
},

We've been using a version of this for about 6 months now, and it seems to cover most use cases where a custom serialize function isn't needed.

@abritinthebay
Copy link

The Node errors would be expected. It's a lot stricter.

@tbranyen
Copy link
Owner

tbranyen commented Sep 9, 2013

@SBoudrias can you rebase this pull request to master? I think we should merge as-is.

@SBoudrias
Copy link
Collaborator Author

There it is!

@tbranyen
Copy link
Owner

tbranyen commented Sep 9, 2013

Hey @SBoudrias feel free to merge once the build passes.

SBoudrias added a commit that referenced this pull request Sep 9, 2013
Default `serialize` implementation (Fix #358)
@SBoudrias SBoudrias merged commit 6220684 into tbranyen:master Sep 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants