Skip to content

Instantly share code, notes, and snippets.

@canonic-epicure
Created October 11, 2010 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

bergmark commented Jun 1, 2011

change require to require('task-joose-nodejs') and add require('kiokujs-backend-couchdb') ?

@canonic-epicure
Copy link
Author

One can use "require('task-joose-nodejs')" but, for now, should keep "use('KiokuJS.Backend.CouchDB'" - because of asynchronous dependencies loading.
The synchronous version of JXND (on node only) is on github, still can't release it..

@alexkwolfe
Copy link

Just curious why you chose to use store(Homer, Marge).andThen(callback) rather than store(Homer, Marge, callback). Also, how does the callback know that Homer and Marge were stored OK? In node.js the first parameter of the callback is conventionally an error, if one occurred or null if not.

@alexkwolfe
Copy link

Also, is KiokuJS meant to replace Joose.Storage which is missing from Joose 3?

@canonic-epicure
Copy link
Author

Kioku is built with JooseX.CPS for asynchronous interfaces: http://joose.it/blog/2011/02/14/joosex-cps-tutorial-part-i/

Its rather complicated currently but allows to have nearly the same abstractions (TRY/CATCH/FINALLY) for async code.

Yes, Kioku can replace Joose.Storage

@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