linkedin/dustjs — pull request #62 by rodw (2012-06-14 20:09:20+00:00)
Title: Passing context object into dust.onLoad callback

I've run into a situation where I would very much like access to the current dust `context` within my `dust.onLoad` callback, and I believe this could be a useful addition in general

(I'd be happy to try to justify the need for and/or perceived value of this change if anyone is interested in seeing more detail, but I'll just describe the change for now.)

This patch accomplishes that with a tiny, backward compatible change to the `dust.load` method and an additional parameter to the `dust.onLoad` callback.

Specifically, I've added an extra parameter to the `onLoad` callback method to hold the current context. For backward compatibility I've added this as a third parameter. For future compatibility I've added this as an entry named `context` within a simple JavaScript map (so that additional parameters could be added in the future without changing the callback method signature).

Before this patch, `dust.onLoad` is expected to have the signature:

dust.onLoad = function(name, callback)

After this patch, `dust.onLoad` is expected to have the signature

dust.onLoad = function(name, callback, extras)

where `extras` is a map, currently containing a single entry (with the name `context` and with the context object passed to `dust.load` as the value).

All existing unit tests (under `make test`) pass both before and after this change.

I've also added a simple unit test for this new behavior.