Skip to content

Instantly share code, notes, and snippets.

@kevsmith
Created December 20, 2009 19:41
Show Gist options
  • Select an option

  • Save kevsmith/260609 to your computer and use it in GitHub Desktop.

Select an option

Save kevsmith/260609 to your computer and use it in GitHub Desktop.
1> {ok, P} = js_driver:new().
{ok, #Port<0.846>}
2> js_driver:define_js(P, {file, "testing.js"}, 5000).
ok
3> js:call(P, "hello", [<<"Kevin">>]).
{ok,<<"Hello, Kevin. The date is 12/20/2009">>}
4> JS = <<"function emit(doc) { return {id: doc[\"id\"], acct:, doc[\"acct\"]}; }">>.
. . .
5> js:define(P, JS).
ok
6> Doc = [{<<"id">>, <<"123">>},
{<<"acct">>, <<"12312348523723">>},
{<<"name">>, <<"Homer Simpson">>}].
. . .
7> js:call(P, "emit", [{struct, Doc}]).
{ok,{struct,[{<<"id">>,<<"123">>},
{<<"acct">>,<<"12312348523723">>}]}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment