Created
August 17, 2011 09:21
-
-
Save orlin/1151166 to your computer and use it in GitHub Desktop.
Backbone.history.start() # see index.coffee - error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class exports.RootView extends Backbone.View | |
el: $ '#container' | |
template: '_.jade' | |
initialize: -> | |
_.bindAll @render | |
render: -> | |
$(@el).empty() | |
$(@el).append jadeify @template | |
# console.log('root view rendered') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a piece of browserified express app | |
# ... | |
browserify = require 'browserify' | |
jadeify = require 'jadeify' | |
bundle = browserify | |
require: [ 'underscore' | |
, 'underscore.string' | |
, 'backbone' | |
, {jquery: 'jquery-browserify'} | |
] | |
entry: ["#{__dirname}/app/index.coffee"] | |
bundle.use jadeify "#{__dirname}/app/templates", | |
watch: true | |
extension: '.jade' | |
# ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window._ = require "underscore" | |
window._.mixin require "underscore.string" | |
require "./helpers.coffee" # = _.mixin(s) | |
window.Backbone = require "backbone" | |
window.jadeify = require "jadeify" | |
window.onload = -> | |
# Backbone app bootstrapping | |
window.app = | |
models: {} | |
collections: {} | |
views: {} | |
initialize: -> | |
this.views.home = new (require './views/_view').RootView() | |
this.router = new (require('./router').ChartraRouter)() # last (it renders upon instantiation) | |
# app.router.navigate 'home', true if Backbone.history.getFragment() is '' | |
app.initialize() | |
# console.log "#" + Backbone.history.getFragment() # ok | |
# Backbone.history.start() # Uncaught TypeError: undefined is not a function | |
# {root: '/', pushState: true, silent: true} | |
# The document is in copletely ready state. | |
if window.document.readyState is 'complete' | |
window.onload() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class exports.ChartraRouter extends Backbone.Router | |
routes: | |
'': "home" | |
blank: "blank" | |
app: window.app | |
initialize: -> | |
this.navigate '', true # @home() | |
# the it | |
home: -> | |
@app.views.home.render() | |
# to illustrate Backbone.history #fail | |
blank: -> | |
$('#container').empty() | |
$('#container').text('blank') |
You don't have to manually patch any libraries to make them browserifiable anymore.
browserify-shim takes care of that for you
Works with all libraries I have encountered so far.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just keep in mind
require(...)
is contentious - many would like to claim it. Right now, I require Ender-ed libs first. Browserify requires next.