OK thanks Dave, good tip.

Unless I'm missing something though, which has been definitely known to happen, 
it appears that it's not an issue with the CoffeeScript code itself. To me it 
looks like the CommonJS CoffeeScript functions don't work whereas their 
Javascript equivalents do.

Consider the following Javascript code:
{
        lib: {
                simple: "exports.callback = function() { return 'Simple' }"
        },
        test: {
                map: "function(doc) { 
emit(require('views/lib/simple').callback(), doc) }"
        }
}

As expected, "Simple" is emitted for the key of every document.

Now the equivalent CoffeeScript code:
{
        lib: {
                simple: "exports.callback = () -> 'Simple'"
        },
        test: {
                map: "(doc) -> emit(require('views/lib/simple').callback(), 
doc)"
        }
}

The view returns no results and an error for every document is printed to the 
log file. For example:
[info] [<0.7270.11>] OS Process #Port<0.96999> Log :: function raised exception 
(new TypeError("require(\"views/lib/simple\").callback is not a function", 
"undefined", 3)) with doc._id 8117

Anyway, hopefully more pieces to the puzzle.

Thanks,
Anthony

On Aug 19, 2013, at 1:27 PM, Dave Cottlehuber <[email protected]> wrote:

> Hi Anthony,
> 
> I can't help personally on this but I suspect you might get more guidance
> on user@ where there's a larger group of potential coffeescripters about.
> 
> A+
> Dave
> 
> 
> On 19 August 2013 22:18, Anthony Kaufman <[email protected]> wrote:
> 
>> Hi everyone, I just wanted to check back on this. Any help for me?
>> 
>> On Aug 16, 2013, at 2:10 PM, Jann Horn <[email protected]> wrote:
>> 
>>> On Fri, Aug 16, 2013 at 11:07:30PM +0200, Jann Horn wrote:
>>>> On Fri, Aug 16, 2013 at 02:03:03PM -0700, Anthony Kaufman wrote:
>>>>> I've been trying to define a CoffeeScript CommonJS Module Function
>> without success. I can translate the same function into Javascript and it
>> works fine. I'm using CouchDB 1.3.1 on Mac OS X Lion.
>>>>> 
>>>>> Here's the CoffeeScript document:
>>>>> {
>>>>>    _id: "_design/test",
>>>>>    language: "coffeescript",
>>>>>    lib: {
>>>>>            say_hello: "exports.callback = (name) -> 'Hello ' + name"
>>>>>    }
>>>>>    test: {
>>>>>            map: "(doc) ->
>>>>>    say_hello = require('views/lib/say_hello').callback
>>>>>    emit(say_hello(doc._id), doc)"
>>>>>    }
>>>>> }
>>>> 
>>>> Isn't the indentation a bit broken there?
>>> 
>>> Sorry, nevermind.
>> 
>> 

Reply via email to