tbranyen / backbone-boilerplate Goto Github PK
View Code? Open in Web Editor NEWA workflow for building Backbone applications.
License: MIT License
A workflow for building Backbone applications.
License: MIT License
right now i'm just checking for relative vs absolute:
maybe something better would be using data-attrs
would be awesome to have a server reload ability
build/config.js
watch: {
tasks: "... reload"
}
and then the server comnd might look something like this
node build/server debug --reload
this would inject a websocket script into the page and whenever the watch command re-triggers it would hit the reload socket which would then refresh the page
✔ Build Tool
✔ Bugs
There are a few bugs that currently exist
Documentation!
Still need considerable amounts. The code comments are great but...
namespace.fetchTemplate
functionBuild tasks
Would like the follow tasks (build plugins):
tasks are fragmented and currently master is running on an old version of grunt.
Hi!
I want to remove all references in global instances in my app, so I'm using this in my config:
use: {
underscore: {
attach: "_"
},
backbone: {
deps: ["use!underscore", "jquery"],
attach: function(_, $) {
// This should work because Backbone should be already loaded.
// Commenting them does not help with the issue anyway.
window._.noConflict();
window.jQuery.noConflict(true);
// Return Backbone object and remove it from global scope as well
return window.Backbone.noConflict();
}
}
this works perfectly during development, but fails in 'debug' (and 'release') versions. When using the 'debug' version I can see a 'Backbone is undefined' error in "app: _.extend({}, Backbone.Events)".
I assume the standard namespace.module()
mechanism is perfectly fine for creating modules that aren't meant to contain Backbone objects. That's what I'm using at the moment.
Might be nice to either have an example, or mention that this is OK / recommended in the docs.
brought up by @wookiehangover should we rename assets to public?
Vote +/- 1 or thumbs up/down.
I'm wondering, is it possible to somehow load another module dynamically which wasn't compiled?
For example, if you want to change app's language/locale on-the-fly, or if it needs to load a special version of music player depending on browser's vendor, or something else.
Update the jquery selector to be this:
a[href]:not([data-bypass])
Just being a bit more explicit here, the main reason right now is twitter's bootstrap alert module, utilizes an empty <a>
tag. So being more explicit and compliant with the twitter bootstrap is just all good.
I'm new to Node, so this might be a common mistake. I followed the startup directions in your readme, but I couldn't get the server to start up:
bburton$ node build/server
Server listening on http://localhost:8000
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: listen EADDRINUSE
at errnoException (net.js:640:11)
at Array.0 (net.js:741:26)
at EventEmitter._tickCallback (node.js:192:40)
My environment is Node v.0.6.7 on Mac OSX 10.6.7.
As requested, here's my feedback and suggestions for the project:
Hope some of this is of help :)
I'd like to configure the templateSettings used by the build process in build/tasks/jst/jst.js (I prefer Mustache-style templates).
It looks I should be able to use "jst.templateSettings" in my build config, but this isn't working as I'd expect:
Is this a bug, or am I using it wrong?
(Very helpful project, thanks!)
I was wondering if there is a recommended way to integrate Handlebars, Underscore, etc. templates?
Most importantly, big thanks to @tbranyen as this boilerplate has gotten me past the tedious structuring and enjoying javascript again.
Hi,
While testing my application, I've run into some small problems using the fetch template function.
If I pass no 'done' callback because I'm using the deferred, it throws an error that no done callback is defined.
Following modifications might help:
fetchTemplate: function(path, done) {
var JST = window.JST = window.JST || {};
var def = new $.Deferred();
// Should be an instant synchronous way of getting the template, if it
// exists in the JST object.
if (JST[path]) {
if(done) {
done(JST[path]);
}
return def.resolve(JST[path]);
}
// Fetch it asynchronously if not available from JST
$.get(path, function(contents) {
JST[path] = _.template(contents);
// Set the global JST cache and return the template
if(done) {
done(JST[path]);
}
// Resolve the template deferred
def.resolve(JST[path]);
}, "text");
// Ensure a normalized return value (Promise)
return def.promise();
},
Currently the index.js includes the following comment:
// Defining the application router, you can attach sub routers here.
However there is no example how this "subrouting" should be done. For clarifying purposes the tutorial related routing could be done in Example.Router, if this is feasible.
Also I would think that it would be more beneficial to arrange all module specific stuff in a single directory, and all its related code in the same JavaScript file. This way if some module needs to be disabled, all that is needed to do is to delete one directory and comment one script including from index.html as well as to comment the module declaration from index.js. Or is there some good explanation why this is not a good idea.
Example needs to be provided with more than just one page(view) and the rest redirects to the original view.
I've created a 2nd view and a template yet am having a nightmare of an issue with routing.
models
example.js
other.js
templates
example.html
other.html
var Router = Backbone.Router.extend({
routes: {
"": "index",
":hash": "index",
"other": "other"
},
index: function(hash) {
var route = this;
var tutorial = new Example.Views.Tutorial();
// Attach the tutorial to the DOM
tutorial.render(function(el) {
$("#main").html(el);
// Fix for hashes in pushState and hash fragment
if (hash && !route._alreadyTriggered) {
// Reset to home, pushState support automatically converts hashes
Backbone.history.navigate("", false);
// Trigger the default browser behavior
location.hash = hash;
// Set an internal flag to stop recursive looping
route._alreadyTriggered = true;
}
});
},
other: function() {
var other = new Example.Views.Other();
// Attach the tutorial to the DOM
other.render(function(el) {
$("#main").html(el);
});
}
});
Yet, what happens is. onclick page redirects to " /#other " then removes # leaving only " /other ". refreshing the page causes 404
@iros got it stuck in my head that we need to get windows support here. the two offending modules are zlib.sync
and glob
. I can live without having the gzip output, so we can easily override that task. The way glob is being used allows it to be easily rewritten in pure js.
perhaps it would be best to maintain a separate fork of grunt assuming this won't get merged upstream?
I've followed the tutorial and, when arrived at the build phase I simply execute:
node build
from the project root and then the build process stops working and warns me:
Running "lint:files" (lint) task
<WARN> Object #<Object> has no method 'relative' Use --force to continue. </WARN>
I've no idea on what's happening. I also checked grunt
github page and didn't find anything useful.
Any advice?
Thanks,
S.
Within the Event section of the Backbone documentation it says:
For example, to make a handy event dispatcher that can coordinate events among different areas of your application: var dispatcher = _.clone(Backbone.Events)
Would it make sense then to add a pub/sub wrapper for this within this.namespace? If there's general interest for this I can submit a pull request. As far as I'm concerned pubsub would be especially helpful in the AMD branch to reduce the number of required modules.
Just downloaded latest example and launched it. There is an error: index.js: Example is not defined.
Chrome's cache is considerably broken when using the node server. I'm going to add a ?timestamp=<unix_timestamp> to every assets request.
the build folder should start fresh every time.
Hi,
I have a general Router with routes like :
routes:{
"": "index",
"signup": "signup",
"createposition/:query": "create",
":hash": "index"
},
When I try to go to the url createposition/:query the url looks like : http://localhost:50633/createposition/0
I have a view rendered in the page :
Position.Views.Create = Backbone.View.extend({
template: "app/templates/position/index.html",
initialize: function () {
this.render();
},
render: function (done) {
var view = this;
// Fetch the template, render it to the View element and call done.
Fiilii.fetchTemplate(this.template, function (tmpl) {
view.el.innerHTML = tmpl();
done(view.el);
});
}
});
When the app fetch the template, it fetch it with the url http://localhost:50633/createposition/app/templates/position/index.html instead of http://localhost:50633/app/templates/position/index.html
Do I have to change the fetch template method to take the full path or am I doing something wrong ?
I try to change the template path to template: "/app/templates/position/index.html" and I get the same error.
At the moment, the debug server hits assets/css. As long as you aren't using a CSS transpiler, this is fine. If you're using LESS, for example, though, you might want to hit a compiled style.css in dist/debug/css during development. The downside of this would be a need for automatic recompilation.
One possible fix would be conditionally including the client-side less compiler via AMD somehow. But, doing that would require that you link to style.less in your index.html, and that would bork the release build (which provides a compiled/minified style.css).
Thoughts?
some thoughts on the view and fetchTemplate function:
I wrote up a ticket suggesting that you take the callback out as it didn't add any value... and just before submitting it, i noticed the use of fetchTemplate
, which is potentially asynchronous.
I think part of why this confused me is that it's a non-standard use of render
. I rarely see people changing the signature of render
, and there's usually some additional framework or plugin that wraps the use of it, when they do.
i tried a few ideas to make this work without needing to modify the signature of render
and i couldn't come up with anything. the asynchronous problem pretty much requires it, unless you're willing to lose encapsulation by moving the render logic out of the view - which is a really bad idea. :P
So, the callback makes sense knowing that - but it took a while for me to realize that. Can you clarify the use of the callback, either through better code commenting and other documentation (which i realize you said you're still working on)?
WIth Backbone 0.9 you need Underscore 1.3.1 or better. The AMD branch currently has 1.3.0 which will cause subtle errors when using some underscore methods.
At least one task and __template.js
test fail.errorcount
. There's a simpler way to do this now, see the canonical uber-simple "basic" task.
Just got started with this project today. I'm very satisfied with it so far. The source is very well documented and I'm finding that structuring my own app based on the Example module is rather straight forward.
One big point of confusion that I've noticed, however, is that the documentation here and in the Example page doesn't actually match the implementation of the code.
Couple of examples:
/app/main.js instead of /app/index.js
Structure of /app/main.js doesn't directly map to the documentation
The arguments being passed into /app/main.js aren't discussed directly anywhere I could find
The existence of app/namespace.js (Seems required but its not mentioned anywhere?)
What templating system is being used? Is it underscore's template? What would be the recommended way to replace it with something like Mustache?
Seems like some of these things were changed or added recently, so getting updated docs would be awesome.
I am trying to make the backbone boilerplate working and I get an error with the stream.js file.
When I execute : build>node server
I go to the url http://localhost:8000 and I get the error below:
stream.js:99
throw er; // Unhandled stream error in pipe.
^
Error: ENOENT, The operation completed successfully.
'./index.html'
My version of node is v0.5.7
Maybe this is just me personally... but I don't like to see object definitions in the jQuery DOMReady function.
In this case, you're saying that the router can't be defined until the DOM is ready, but I don't see any code in the router that needs the DOM before a route is fired.
I'd move the router definition outside of the jQuery function. Possibly put it in the this.namespace
object directly or hide it in another module somewhere else.
I'm sorry if I missed it in the docs some place, but is there a forum set up for the boilerplate (i.e., google groups or yahoo groups)? I think it would be nice to have a place to ask questions and post comments outside of the issues list. I would think the issues list should be devoted just to bugs/features, but maybe I'm just not familiar enough with the github Zeitgeist.
It would be nice to use h5bp/node-build-script in the future. (for now it is probably not ready)
It has: reving + usemin tasks
Server for production and staging.
dev branch is better for testing.
The boilerplate conveniently has a placeholder for a namespace.
In the AMD branch it is currently implemented as a module and being included as a dependency for the rest of the modules.
There is nothing wrong with this approach but there is also another alternative worth looking into - exposing the namespace as a global object. An example for this scenario is Addy Osmani's backbone-mobile-search:
https://github.com/addyosmani/backbone-mobile-search
Any opinions on what approach would be better?
I think most of the current example tutorial belongs in the Wiki. What I'd really like is an interactive way to customize the boilerplate, kind of like a step-by-step approach.
Thoughts?
Running a very simple setup gives:
Uncaught TypeError: Object [object Object] has no method 'module'
where [object Object]
was defined as my this.namespace
could someone help me out with this?
Hi,
I was just trying to give this project a swirl, because I'm trying to figure out a clean way to bootstrap new projects. As a way to learn I'm cloning it into subfolder of an existing project to see how well it integrates.
If I launch the node.js server in that subfolder, it works great,
However, for some reason I get a clean,white page (no modifications done, except for changing the absolute paths in the index.html page to relative ones (added a dot in there). I don't get any 404's nor javascript errors, so something must be off, but I can't seem to figure out what.
Any help appreciated.
Koen
what's the difference between the top level namespace and the individual models created within it?
what would i organize where, when using this as a starting point?
maybe it's just the small, "example" nature of the code here, but i don't see a clear distinction of what should go where at the moment.
grunt will now load tasks and ignore node_modules
the structure would look something like this:
tasks
/subtask/node_modules
/subtask/subtask.js
Need to write a script that will autoload these sub folders.
After looking over @rmurphey's project and seeing that she uses fetchTemplate and chains a then
off it (which was breaking under a build) this should be updated to always return a deferred so that it will work in built files too.
I was wondering if there is an example available on how to approach files that are served by the node server as part of an npm module (e.g. socket.io)? If it is single javascript file, then copying it into the client-side app's js/libs folder is not a big deal, but for something larger like socket.io-client, it seems messy to duplicate the files.
Is there a better way?
I think it might be cool to have a review of popular plugins
So, how about i18n dynamic loader support?
Setting the host parameter to 0.0.0.0 allows node to bind to all available IP's and the site can be accessed from the network.
Here's the pull request:
iguana@3672bdd
see #18
Unless somebody else beats me to it.
this will allow people using node already to easily get the latest boilerplate into their project
this is in no way required to use the boilerplate
Similar to the last one, it would be nice to have an example of the 'recommended' way to override Backbone classes and methods (i.e. extend them to make new 'base classes' that can be used to instantiate actual object instances).
At the moment, I'm not using the namespace.module()
method to create modules for these classes. If there's a nice way to do that, I'd love to see it.
In the build for our app, I made it so that it copies the entire project - images, documents, stylesheets and all - over into the production directory, unless files are specified in config to be ignored (like readme, static API snapshots, other dev things etc.)
This enables me to scp
the entire project in one go without having to move anything around.
Sure you can run the nodeJS server via node build/server debug
and it will automatically pull the minified files from the /dist
directory, but I don't imagine many people will use the nodeJS server in production, so that means they'll have to do some wrangling each and every time they build the project (which could be every time something is changed, if they're using the watcher)
This would work well as a config setting. Result is that after building, you know the entire application is ready to rock and/or upload in one go!
Also allows you to run build extensions or plugins on any other type of file in the project as part of it. Some people run scripts on their images - we definitely run optimisations on our underscore/HTML templates, add license blocks to all files, clean up unnecessary (inlined) dependencies, etc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.