Created
August 30, 2009 16:28
-
-
Save bluescreen303/178034 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
// map function | |
function(op) { | |
if(op.channel) { | |
emit(op.channel, op); | |
} | |
} | |
// reduce | |
function(keys, ops, rereduce) { | |
if(rereduce) { | |
// still need to do this | |
} else { | |
var channels = {}; | |
ops.forEach(function(op) { | |
var channel = (channels[op.channel] = channels[op.channel] || {channel: op.channel, users: []}); | |
if(op.operation == "join") { | |
if(channel.users.indexOf(op.property) == -1) channel.users.push(op.property); | |
} | |
}); | |
return channels; | |
} | |
} | |
// example operations | |
{ | |
"_id": "b3af688ce356487f5ca3176400edd87c", | |
"_rev": "1-78203bea28805a6c97544b71d89ae09b", | |
"operation": "join", | |
"property": "mathijs", | |
"channel": "couchdb" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment