Created
October 11, 2010 14:23
-
-
Save canonic-epicure/620582 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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') | |
}) | |
}) | |
Also, is KiokuJS meant to replace Joose.Storage which is missing from Joose 3?
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
Just curious why you chose to use
store(Homer, Marge).andThen(callback)
rather thanstore(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 ornull
if not.