Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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 commented Jun 1, 2011

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

Owner

SamuraiJack commented Jun 2, 2011

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..

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.

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

Owner

SamuraiJack commented Jan 23, 2012

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

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