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

Stop using toJSON for rendering templates #1476

Closed
jamesplease opened this issue Jun 11, 2014 · 7 comments
Closed

Stop using toJSON for rendering templates #1476

jamesplease opened this issue Jun 11, 2014 · 7 comments
Milestone

Comments

@jamesplease
Copy link
Member

Right now we're using toJSON to render templates.

Per this issue, and its resolution, we shouldn't be.

Instead, we should be cloning the attributes object for our templates explicitly. I'm talking _.clone(model.attributes).

Your next question might be...why does this matter at all? toJSON does the exact same thing...all it does is clone the attributes.

The difference is use cases. toJSON is called when you're persisting data to the server – it's meant to filter out any data you don't want to save. It's not at all meant to be used in views!

This lets you do things like:

  1. Get data back from the server that has time stored as a string
  2. Store that data as a moment in your model, within attributes
  3. Filter that out with toJSON
  4. Still have access to everything in render

This is a breaking change, but is necessary to get Marionette consistent w. Backbone. It'll also be a huge help to everyone who is trying to do something like the above, which is otherwise really difficult.

@samccone
Copy link
Member

👍

@jamesplease
Copy link
Member Author

ha this is already done

Thanks @thejameskyle for pointing that out :)

@cmaher
Copy link
Member

cmaher commented Jul 16, 2014

closing in favor of #1599

@cmaher cmaher closed this as completed Jul 16, 2014
@jamesplease
Copy link
Member Author

@cmaher, I think #1599 references the non-breaking change for v2.x, where we're still using toJSON, just in a manner that prepares us for this. This issue documents the ultimately breaking change where we swap out toJSON in 3.x.

@samccone
Copy link
Member

fixed in #1659

@jamesplease
Copy link
Member Author

Reopening – this references a breaking change that can't happen until v3, hence the milestone.

@jamesplease jamesplease reopened this Aug 30, 2014
@jamesplease
Copy link
Member Author

Added to #1796

jamesplease added a commit that referenced this issue Jan 7, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jamesplease added a commit that referenced this issue Jan 7, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jamesplease added a commit that referenced this issue Jan 7, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jamesplease added a commit that referenced this issue Jan 7, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jamesplease added a commit that referenced this issue Jan 7, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jamesplease added a commit that referenced this issue Jan 7, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jamesplease added a commit that referenced this issue Jan 29, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jamesplease added a commit that referenced this issue Jan 30, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jamesplease added a commit that referenced this issue Feb 4, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves #1476
jasonLaster pushed a commit to jasonLaster/backbone.marionette that referenced this issue Mar 25, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves marionettejs#1476
jasonLaster pushed a commit to jasonLaster/backbone.marionette that referenced this issue Mar 25, 2015
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

Resolves marionettejs#1476
ahumphreys87 pushed a commit to ahumphreys87/backbone.marionette that referenced this issue Aug 21, 2016
toJSON should only be used for preparing data to be sent to the
server. In addition, serializeData no longer accepts arguments,
distinguishing it further from templateHelpers.

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

No branches or pull requests

3 participants