hinoki-trace

tracing for functions returned by hinoki factories

Usage no npm install needed!

<script type="module">
  import hinokiTrace from 'https://cdn.skypack.dev/hinoki-trace';
</script>

README

hinoki-trace

NPM version Build Status Dependencies

tracing for functions returned by hinoki factories

  • built-in support for promise-returning functions
  • works in node.js and the browser
  • hinoki-trace makes debugging hinoki applications a blast :)

node.js setup

npm install hinoki-trace
var hinokiTrace = require('hinoki-trace');

browser setup

your markup should look something like the following

<html>
  <body>
    <!-- content... -->

    <!-- hinoki requires bluebird -->
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/bluebird/1.2.2/bluebird.js"></script>
    <!--
      hinoki-trace obviously requires hinoki
      take src/hinoki.js from the hinoki repository and include it
    -->
    <script type="text/javascript" src="hinoki.js"></script>
    <!-- take src/hinoki-trace.js from this repository and include it -->
    <script type="text/javascript" src="hinoki-trace.js"></script>
    <script type="text/javascript" src="example.js"></script>
  </body>
</html>

hinoki-trace.js makes the global variable hinokiTrace available

its best to fetch bluebird with bower, hinoki with npm, hinoki-trace with npm, and then use a build system like gulp to bring everything together

example.js

trace output on the console looks like this:

TRACE          0 | squared | <- [ 1 ]
TRACE          1 | times | <- [ 1, 1 ]
TRACE          1 | times | -> 1
TRACE          0 | squared | => promise
TRACE          2 | squared | <- [ 2 ]
TRACE          3 | times | <- [ 2, 2 ]
TRACE          3 | times | -> 4
TRACE          2 | squared | => promise
TRACE          4 | squared | <- [ 3 ]
TRACE          5 | times | <- [ 3, 3 ]
TRACE          5 | times | -> 9
TRACE          4 | squared | => promise
TRACE          6 | squared | <- [ 4 ]
TRACE          7 | times | <- [ 4, 4 ]
TRACE          7 | times | -> 16
TRACE          6 | squared | => promise
TRACE          8 | squared | <- [ 5 ]
TRACE          9 | times | <- [ 5, 5 ]
TRACE          9 | times | -> 25
TRACE          8 | squared | => promise
TRACE          0 | squared | => 1
TRACE          4 | squared | => 9
TRACE          2 | squared | => 4
TRACE          8 | squared | => 25
TRACE          6 | squared | => 16

todo

  • add support for performance profiling
    • build on top instead of built-in
  • document options (callback and nextTraceId)
  • make it possibly to register a different handler for each traced function by passing an object instead of an array
    • a value of true just uses the default handler
  • support not just factories but tracing of values which are functions as well
  • make the example more interesting
  • add timestamps to trace output

license: MIT