There was some recent discussion asking if we could formalize the weird script tag hack we have in place for grabbing extra data passed along from the Perl. (i.e. we parse the api call <script> tag to pull out useful information, like the parsed query)
I don't want us to formalize that weird hack and remembered that I had experimented with the call_data parameter before. Now that we're passing Perl data to the front end for Goodies I decided to take another stab at this, using the DDG.inject function, which we use internally in a similar fashion.
Result
This should allow us to easily pass extra data from Perl along to a front end Spice IA object.
I've tested this and it seems to be working correctly, getting it to work internally will really prove my theory.
Testing
To test this, I modified the NPM Spice's handle function to:
You can test this PR by checking out that Spice branch and running duckpan -I ../p5-app-duckpan/lib server, the triggering the NPM Spice with npm colors. The console will contain the Spice Data object passed from the Perl
@zachthompson I'd like to hear your thoughts on this
Background
There was some recent discussion asking if we could formalize the weird script tag hack we have in place for grabbing extra data passed along from the Perl. (i.e. we parse the api call
<script>
tag to pull out useful information, like the parsed query)I don't want us to formalize that weird hack and remembered that I had experimented with the
call_data
parameter before. Now that we're passing Perl data to the front end for Goodies I decided to take another stab at this, using theDDG.inject
function, which we use internally in a similar fashion.Result
This should allow us to easily pass extra data from Perl along to a front end Spice IA object.
I've tested this and it seems to be working correctly, getting it to work internally will really prove my theory.
Testing
To test this, I modified the NPM Spice's
handle
function to:And updated the JS to log the
call_data
withconsole.log(Spice.npm.call_data);
which worked as expected:The code for the modified NPM Spice is on GitHub here: https://github.com/duckduckgo/zeroclickinfo-spice/compare/zaahir/spice-call-data-example
You can test this PR by checking out that Spice branch and running
duckpan -I ../p5-app-duckpan/lib server
, the triggering the NPM Spice withnpm colors
. The console will contain the Spice Data object passed from the Perl@zachthompson I'd like to hear your thoughts on this