Skip to content

Instantly share code, notes, and snippets.

@canonic-epicure
Created October 11, 2010 14:23
Show Gist options
  • Save canonic-epicure/620582 to your computer and use it in GitHub Desktop.
Save canonic-epicure/620582 to your computer and use it in GitHub Desktop.
require('Task/Joose/NodeJS')
use('KiokuJS.Backend.CouchDB', function () {
// class declaration
Class('Person', {
has : {
self : null,
name : null,
spouse : null
},
methods : {
initialize : function () {
this.self = this
}
}
})
// arbitrary data structure
var Homer = new Person({
name : "Homer"
})
var Marge = new Person({
name : "Marge"
})
Homer.spouse = Marge
Marge.spouse = Homer
// handler setup
var handle = new KiokuJS.Backend.CouchDB({ dbURL : 'http://local/5984/demo' })
var scope = handle.newScope()
// storing
scope.store(Homer, Marge).andThen(function (homerID, margeID) {
var puts = require('sys').puts
puts('Stored ok')
})
})
@bergmark
Copy link

I can think of a few advantages for not having the callback as the last arg, it's kind of awkward since store can take an arbitrary number of arguments (what if you want no callback but you want to store a function?). Also it allows you to not execute the store call immediately, it will be suspended until you call andThen() or now()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment