Why use Spine?
Spine loads record data from couchdb into browser memory. When you manipulate records, they are changed in-memory and then synced to couchdb behind the scenes. This means the UI is never blocked and data update events propagate through your app instantly.
Example
A Kanso port of spine.todos lives here.
Usage
Add spine-adapter to your dependencies in kanso.json and run kanso install.
"dependencies": {
"spine-adapter": null
}
require Spine modules you'll use. spine/core is required for any use of Spine. spine-adapter/couch-ajax is required to persist your models in couchdb.
# Creates the global 'Spine' object
require("spine/core") # you could also use require("spine/spine")
require("spine-adapter/couch-ajax")
class BlogPost extends Spine.Model
@configure "BlogPost", "title", "body"
# Enables CouchDB storage for instances of this model
@extend Spine.Model.CouchAjax
To fetch a specific set of records (rather than all records of a type), use the db module to retreive a view. Pass the docs from that view to the model's refresh method.
require("db")
require("settings/root")
_ = require("underscore")._
query =
include_docs: yes
start_key: [1323286277322]
end_key: [1323286977322, {}]
refresh = () ->
appdb = db.use(require('duality/core').getDBURL())
appdb.getView settings.name, "posts_by_date", query, (err, res) ->
BlogPost.refresh(_.pluck(res.rows, "doc")) if res?.rows
Instantiate your Spine app controller in a script tag. In this example, the module at controllers/app exports a Spine controller.
<!-- in base.html -->
...
<div id="content"></div>
<script type="text/javascript" charset="utf-8">
var exports = this;
jQuery(function(){
var App = require("controllers/app");
exports.new_app = new App({el: $("#content")});
});
</script>
</body>
</html>
For full documentation of how to use Spine, visit its official documentation.