Last active
February 9, 2017 07:09
-
-
Save wearhere/d5054955ad7571ec5d50165228ac3a25 to your computer and use it in GitHub Desktop.
Backbone + Ractive + Rollup
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
const ractive = require('rollup-plugin-ractive'); | |
// Rollup plugins | |
let plugins = [ | |
// Note that we could keep Handlebars in for views where we didn't want to (yet) use Ractive. | |
// That's why the file extension isn't HTML. | |
ractive({ | |
extensions: ['.ract'] | |
}) | |
]; |
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
<h1>Hello, {{ titlecase(name) }}</h1> |
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
const HelloWorldModel = Backbone.Model.extend({ | |
defaults: { | |
name: null | |
} | |
}); |
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
import Template from './HelloWorld.ract'; | |
const HelloWorldView = Backbone.View.extend({ | |
render() { | |
this.ractive = new Ractive({ | |
el: this.el, | |
template: Template, | |
data: this.model, | |
adapt: [ 'Backbone' ] | |
}); | |
return this; | |
} | |
}); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="//cdn.jsdelivr.net/g/ractive@0.8.10(ractive.runtime.min.js),ractive.adaptors-backbone@0.3.0,backbonejs@1.3.3,underscorejs@1.8.3,jquery@3.1.1"></script> | |
</head> | |
<body> | |
<div id="main"></div> | |
</body> | |
</html> |
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
import HelloWorldModel from './HelloWorldModel.js'; | |
import HelloWorldView from './HelloWorldView.js'; | |
let model = new HelloWorldModel({ name: 'jeff' }); | |
new HelloWorldView({ | |
el: $('#main'), | |
model | |
}).render(); | |
setTimeout(() => { | |
model.set('name', 'brad'); | |
}, 2000); |
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
_.extend(Ractive.defaults.data, { | |
titlecase(string) { | |
if (!string) return string; | |
return string[0].toUpperCase() + string.slice(1); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment