bones icon indicating copy to clipboard operation
bones copied to clipboard

Upgrade to backbone 0.9.1 and underscore 1.3.1

Open asparagino opened this issue 13 years ago • 4 comments
trafficstars

Hi - we've just put a few hours into upgrading our forked copy of bones to work with backbone 0.9.1 (latest) and underscore 1.3.1.

I'll attempt to add a patch to this comment, but the highlights follow below:

  1. Obviously the versions need to be bumped in Package.json
  •    "underscore": "1.1.x",
    
  •    "underscore": "1.3.x",
     "express": "2.4.4",
    
  •    "backbone": "0.5.1",
    
  •    "backbone": "0.9.1",
    
  1. in bones.js, set the server side jquery library into the imported backbone. Backbone now requires $ to be set, and the previous version was not loading it.

bones.js: exports.Backbone = require('bones/server/backbone'); +exports.Backbone.setDomLibrary(exports.$);

  1. In plugin.js around lines 56/55 templates must now be passed to the client as a variable, as they're hidden using closure in the new _.template method.
  •            content: 'template = ' + module.exports + ';'
    
  •            // client must now pass escaped template content over, as _ makes it a hidden closure var
    
  •            content: 'var content = \''+escape(content)+'\';template = _.template(unescape(content));'
    

There are some changes to the example app that need to be made to work with these, but these 3 items are the show stoppers and only changes to the bones project core that we needed to make things work again. We made changes in our own app rather than updating the example, so unfortunately I can't share those, but the above should work as a leg up for anyone starting to upgrade the backbone version.

asparagino avatar Feb 07 '12 21:02 asparagino

diff --git a/bones.js b/bones.js
index bb70f11..093218d 100644
--- a/bones.js
+++ b/bones.js
@@ -4,6 +4,7 @@ if (global.__BonesPlugin__) {
 }

 exports.$ = require('jquery');
+
 exports._ = require('underscore');
 exports.mirror = require('mirror');

@@ -13,6 +14,8 @@ exports.middleware = require('bones/server/middleware');
 exports.server = true;

 exports.Backbone = require('bones/server/backbone');
+exports.Backbone.setDomLibrary(exports.$);
+
 exports.Router = require('bones/server/router');
 exports.Model = require('bones/server/model');
 exports.Collection = require('bones/server/collection');
diff --git a/package.json b/package.json
index 8dbb019..8d182b6 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
     "name": "bones",
     "description": "Framework for using backbone.js on the client and server.",
-    "version": "2.0.0alpha4",
+    "version": "2.0.0alpha4-bg0.1",

     "author": {
       "name": "Development Seed",
@@ -12,9 +12,9 @@
     "main": "./bones.js",

     "dependencies": {
-        "underscore": "1.1.x",
+        "underscore": "1.3.x",
         "express": "2.4.4",
-        "backbone": "0.5.1",
+        "backbone": "0.9.1",
         "jquery": "1.6.x",
         "optimist": "0.1.x",
         "mirror": "0.3.x"
diff --git a/server/middleware.js b/server/middleware.js
index 5139ef0..813542d 100644
--- a/server/middleware.js
+++ b/server/middleware.js
@@ -96,6 +96,7 @@ exports['showError'] = function showError() {

 exports['notFound'] = function notFound() {
     return function notFound(req, res, next) {
-        next(new Error.HTTP(404));
+       var error = new Error.HTTP('Not found: '+req.originalUrl,404);
+        next(error);
     };
 };
diff --git a/server/plugin.js b/server/plugin.js
index 2f668c4..3d67080 100644
--- a/server/plugin.js
+++ b/server/plugin.js
@@ -36,7 +36,6 @@ require.extensions['.bones'] = function(module, filename) {
     }
 };

-
 // Default template engine.
 require.extensions['._'] = function(module, filename) {
     var content = fs.readFileSync(filename, 'utf8');
@@ -56,7 +55,8 @@ require.extensions['._'] = function(module, filename) {
         if (app.assets && !(/\.server\._$/.test(filename))) {
             app.assets.templates.push({
                 filename: filename,
-                content: 'template = ' + module.exports + ';'
+                // client must now pass escaped template content over, as _ makes it a hidden closure var
+                content: 'var content = \''+escape(content)+'\';template = _.template(unescape(content));'
             });
         }
     };

diff --git a/server/utils.js b/server/utils.js
index cb52ac2..3ef6eb2 100644
--- a/server/utils.js
+++ b/server/utils.js
@@ -94,7 +94,9 @@ Error.HTTP = function(message, status) {
     }

     Error.call(this, message);
-    Error.captureStackTrace(this, arguments.callee);
+    if (status !== 404) {
+       Error.captureStackTrace(this, arguments.callee);
+    }
     this.message = message;
     this.status = status;
 };

asparagino avatar Feb 07 '12 21:02 asparagino

For upgrading to underscore 1.3.x, I think you just need the compiled template source, as in the commit:

https://github.com/Wiredcraft/bones/commit/38825217107ae7d9f207ccc4446799f965f547a3

Again, please consider #51 so I can send pull requests. The master branch doesn't work at the moment.

makara avatar May 10 '12 07:05 makara

This is my commit to upgrade to backbone 0.9.2 , on top of @makara's fix. It was based on @asparagino's fix.

https://github.com/EmbarkSystems/bones/commit/732b1b89f76b4b7df58e9e0eb5c1282c586fc1ef

AdrianRossouw avatar May 15 '12 00:05 AdrianRossouw

Hi Adrian,

I'm really glad my patches have found some use. I'm not actively working with bones now. I like the project and it seems pretty solid, but there's some complexity and a harsh learning curve hit when using it outside devseed. Our team kept finding that we were having to choose older node or npm dependencies or spend time going through bones itself to make it do what we wanted, which made it a framework that swallowed time. Documentation, development momentum and project team around the project made it feel like a devseed internal project that happened to be open source, rather than a project with an active community and projects using it outside devseed.

We ended up rolling several of the concepts we needed for backbone.js<->node.js integration into our own express based project and learnt a lot from bones while we were using it, so definitely got some value from it! I'll keep an eye on the project now you're making things happen and may give it another shot in the future.

  • Pete (asparagino)

On Mon, May 14, 2012 at 5:48 PM, Adrian Rossouw < [email protected]

wrote:

This is my commit to upgrade to backbone 0.9.2 , on top of @makara's fix. It was based on @asparagino's fix.

https://github.com/EmbarkSystems/bones/commit/732b1b89f76b4b7df58e9e0eb5c1282c586fc1ef


Reply to this email directly or view it on GitHub: https://github.com/developmentseed/bones/issues/43#issuecomment-5705962

asparagino avatar May 15 '12 16:05 asparagino