Skip to content

Latest commit

 

History

History
39 lines (26 loc) · 1.36 KB

hooks.md

File metadata and controls

39 lines (26 loc) · 1.36 KB

Hooks

See also plugins.

Extra scripts

You can configure REMS to include extra script files by defining configuration such as:

 :extra-scripts {:root "/tmp" :files ["/scripts/foo.js"]}

This means the script will be served from /tmp/scripts/foo.js on your local filesystem. The browser sees only the /scripts/foo.js part.

There you can for example initialize your analytics scripts.

Event hooks

If you want to hook code into additional events you can include a script file like the following. REMS will attempt to call hooks for get, put and navigate events, if they exist.

function logIt(e) {
  // e.g. call your analytics solution here
  console.log(e);
}

window.rems_hooks = {};
window.rems_hooks.get = logIt;
window.rems_hooks.put = logIt;
window.rems_hooks.navigate = logIt;

window.rems_hooks.get is called when more data is fetched from the API. window.rems_hooks.put is called when a command is sent to the API. window.rems_hooks.navigate is called whenever the Single-Page App changes page i.e. route.

All callbacks get the request path as first parameter. Both get and put callbacks get an additional parameter that is a map containing other request parameters. You can find query parameters and such from there.

At the moment, manipulation of the query is not possible. Neither is accessing the response.