incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alexander Shorin <kxe...@gmail.com>
Subject Re: CommonJS in views (aka OpenPGP inside a map function)
Date Tue, 03 Jul 2012 02:59:39 GMT
> Is there some way to debug 'requires'?  There's no real error other that someobject.someexportedfunction
doesn't exist.
> Hence I'm not able to figure out what's wrong with the library since I needed to 'hack'
it a bit to export the objects I needed access.

You could explore ddoc(for views it just very limited by "views/lib"
branch) from any CommonJS module through `module` variable. It
contains `id` property that tells you where you are, `current` that
points to current frame, `parent` that points to parent frame and
`export` that has alias as same name variable.

Since then you could inspect your modules as normal Javascript code.
But beware, because you could easily be trapped into recursive link
loop and already executed modules(via require) couldn't be dumped to
JSON due to module cache.

--
,,,^..^,,,


On Tue, Jul 3, 2012 at 6:24 AM, Jim Klo <jim.klo@sri.com> wrote:
> I think I must have had a typo or something... the example now works...
>
> now going to something more sophisticated... (too big for here...)  but I think i've
tracked it down to a bug in one of my other modules...
>
> https://github.com/jimklo/TheCollector/blob/master/dataservices/thecollector-resources/views/lib/sig_utils.js#L47
>
> Is there some way to debug 'requires'?  There's no real error other that someobject.someexportedfunction
doesn't exist.
> Hence I'm not able to figure out what's wrong with the library since I needed to 'hack'
it a bit to export the objects I needed access.
>
> FWIW: I've got what I need to work prototyped in SpiderMonkey here: https://gist.github.com/3036199
now trying to translate to CouchDB with this project. (DCH: This might interest you... I recall
you asking me about OpenPGP inside Map Reduce...)
>
> Thanks,
>
> - Jim
>
> Jim Klo
> Senior Software Engineer
> Center for Software Engineering
> SRI International
>
> On Jul 2, 2012, at 6:52 PM, Alexander Shorin wrote:
>
> Hi!
>
> Your case works for me for 1.2.0 release and 1.3.0@master. What result you got?
>
> --
> ,,,^..^,,,
>
>
> On Tue, Jul 3, 2012 at 5:38 AM, Jim Klo <jim.klo@sri.com<mailto:jim.klo@sri.com>>
wrote:
> Hi,
>
> I have a question regarding CommonJS within views..
>
> Should this work, or is it a bug that it doesn't?  Using CouchDB 1.2.0
>
> {
> _id: "_design/commonjs-test",
> views: {
> lib: {
> include1: "var include2 = require('views/lib/include2');  exports.foo1 = include2.foo2;",
> include2: "exports.foo2 = 42"
> },
> my_view: {
> map: "function(doc) { emit( require('views/lib/include1').foo1, null); }"
> }
> }
>
> }
>
> If it should work what might I be doing wrong?
>
> Thanks,
>
> Jim Klo
> Senior Software Engineer
> Center for Software Engineering
> SRI International
>
>

Mime
View raw message