Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#26799 closed enhancement (fixed)

Update to Backbone.js 1.1.0

Reported by: ericlewis's profile ericlewis Owned by: nacin's profile nacin
Milestone: 3.9 Priority: normal
Severity: normal Version:
Component: External Libraries Keywords: has-patch
Focuses: Cc:

Description

Backbone.js 1.1.0 was released in Oct 10, 2013.

Attachments (5)

26799-01.patch (126.6 KB) - added by gcorne 11 years ago.
26799-01.2.patch (126.6 KB) - added by gcorne 11 years ago.
26799-02.patch (126.7 KB) - added by gcorne 11 years ago.
26799-03.patch (126.6 KB) - added by gcorne 11 years ago.
26799-04.diff (142.3 KB) - added by georgestephanis 11 years ago.

Download all attachments as: .zip

Change History (22)

#1 @ericlewis
11 years ago

I accidentally started working with 1.1.0 today, and came across an issue with the WP Media experience.

I tried basic boilerplate for creating a media modal that didn't work.

Error I got:

Uncaught TypeError: Cannot read property 'states' of undefined in media.view.Frame._createStates()

I assume the issue is this:

Backbone Views no longer automatically attach options passed to the constructor as this.options and Backbone Models no longer attach url and urlRoot options, but you can do it yourself if you prefer.

#2 @ericlewis
11 years ago

  • Component changed from General to External Libraries
  • Type changed from defect (bug) to enhancement

@gcorne
11 years ago

@gcorne
11 years ago

@gcorne
11 years ago

#3 @gcorne
11 years ago

  • Keywords has-patch added

I took a look at this and was able to put together an initial patch.

For reference, here are the changes between 1.0 and 1.1:

  • Made the return values of Collection’s set, add, remove, and reset more useful. Instead of returning this, they now return the changed (added, removed or updated) model or list of models.
  • Backbone Views no longer automatically attach options passed to the constructor as this.options and Backbone Models no longer attach url and urlRoot options, but you can do it yourself if you prefer.
  • All “invalid” events now pass consistent arguments. First the model in question, then the error object, then options.
  • You are no longer permitted to change the id of your model during parse. Use idAttribute instead.
  • On the other hand, parse is now an excellent place to extract and vivify incoming nested JSON into associated submodels.
  • Many tweaks, optimizations and bugfixes relating to Backbone 1.0, including URL overrides, mutation of options, bulk ordering, trailing slashes, edge-case listener leaks, nested model parsing…

The attachment:26799-02.patch (the two earlier patches were false starts) includes:

  • Upgrades Backbone to 1.1 and Underscore to 1.5.2
  • Switches to un-minified versions of both for development. (It would be nice if we could do this for all of the third-party libraries even if it means coming up with some sort of constant that is used when running from a checkout of develop.svn.wordpress.org to minimize the impact on package size)
  • Adjustments needed to deal with issues that arose due to the first two items in the above change log.

#4 @jorbin
11 years ago

I worry about updating a library that contains backwards incompatible changes. We've avoided updating Masonry in the past due to the this. Updating our libraries with backwards incompatible changes has a decent change to break plugins and themes and is something we should avoid doing.

I think we either need to create a wrapper or work with the upstream libraries to ensure they maintain backwards compatibility.

#5 @gcorne
11 years ago

I understand your point of view and think that it would be worthwhile for someone to open a dialog with Jeremy or one of the other Backbone leads. Since version 1.1 has already been released, I think we shouldn't delay updating because the delay will mean that plugin authors writing new code may write in a style that is only compatible with older versions of Backbone. The good news is that if plugin authors are taking advantage of wp.Backbone.View, the change to no longer automatically attach this.options won't cause problems. We could consider adding wrappers for Backbone.Model and Backbone.Collection to provide us with a way to try and avoid backwards-compatibility issues, but that won't help Backbone code that has already been written.

We also could explore using wp.Backbone = Backbone.noConflict() so that it is easier for plugin authors to supply their own version of Backbone should they choose.

Version 0, edited 11 years ago by gcorne (next)

#6 @gcorne
11 years ago

  • Milestone changed from Awaiting Review to 3.9

This ticket was mentioned in IRC in #wordpress-dev by gcorne. View the logs.


11 years ago

@gcorne
11 years ago

#8 @gcorne
11 years ago

Added a refreshed patch as attachment:26799-03.patch.

This ticket was mentioned in IRC in #wordpress-dev by georgestephanis. View the logs.


11 years ago

#10 @georgestephanis
11 years ago

Underscore 1.6 just shipped, updating the patch momentarily.

https://github.com/jashkenas/underscore/releases

#11 follow-up: @georgestephanis
11 years ago

@gcorne -- it looked like you had added the uncompressed backbone and removed the min version in your previous patch, so I duplicated that for underscore. Unsure if we should just use their versions either with or without the .min.map -- I left it off, as that seemed to be where we were going after the jQuery discussion and r25072

This ticket was mentioned in IRC in #wordpress-dev by DH-Shredder. View the logs.


11 years ago

#13 in reply to: ↑ 11 ; follow-up: @gcorne
11 years ago

Replying to georgestephanis:

@gcorne -- it looked like you had added the uncompressed backbone and removed the min version in your previous patch, so I duplicated that for underscore.

My thought was that we would rely on the build process grunt build to create the minified versions. Whether or not we actually ship with both compressed and uncompressed versions is up for discussion, but personally I find having the uncompressed versions super helpful during development.

#14 in reply to: ↑ 13 @nacin
11 years ago

Per IRC: We're doing this.

Replying to gcorne:

My thought was that we would rely on the build process grunt build to create the minified versions.

We usually prefer to use a library's official minified version, rather than our own. But I have an idea here.

#15 @nacin
11 years ago

In 27170:

Update Backbone from 1.0 to 1.1.

Also update Underscore to 1.6. Includes the development versions of both, which are not included in the build.

Here is Backbone's changelog:

  • Made the return values of Collection’s set, add, remove, and reset more useful. Instead of returning this, they now return the changed (added, removed or updated) model or list of

models. (This means they can no longer be chained.)

  • Backbone Views no longer automatically attach options passed to the constructor as this.options and Backbone Models no longer attach url and urlRoot options, but you can do it yourself if you prefer. (But if you extend wp.Backbone.View, options will be attached for you.)
  • All "invalid" events now pass consistent arguments. First the model in question, then the error object, then options.
  • You are no longer permitted to change the id of your model during parse. Use idAttribute instead.
  • On the other hand, parse is now an excellent place to extract and vivify incoming nested JSON into associated submodels.

See [27171] (next commit) for changes made to WordPress to be compatible with Backbone 1.1.

props gcorne, georgestephanis.
see #26799.

#16 @nacin
11 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 27171:

Update media-views and wp.Backbone.View for Backbone 1.1.

  • Collection set/add/remove/reset methods now return models, not this, so they can no longer be chained.
  • Options passed to Backbone.View's constructor are no longer attached automatically. wp.Backbone.View now does this automatically.

See [27170] for Backbone 1.1 itself.

props gcorne.
fixes #26799.

#17 @nacin
11 years ago

Updated to 1.1.2 in #27182, also for 3.9.

Note: See TracTickets for help on using tickets.