koa-client-actions v1.0.1
Connect version: https://gitlab.com/IanWizard/connect-client-actions
koa-client-actions
A middleware for passing actions back to a client via a non-intrusive header.
This is good for situations where the response body contains actual data, but you still want to use the response to trigger some action or state change on the client. This is meant to be used with the frontend library ClientActions.js: https://gitlab.com/IanWizard/ClientActions.js
Installation
npm install koa-client-actions
Usage
Actions and any arguments are stored in an array, which is passed through the X-Client-Actions header, to the client. Adding actions to the header is as simple as calling the .clientAction method on the context:
var client_actions = require("koa-client-actions");
app.use(client_actions);
app.use(function* () {
this.clientAction("some action", "argument 1", 17, "third arg");
this.clientAction("another action");
this.body("We did awesome stuff.");
});
All actions and arguments are passed through JSON.stringify, so you cannot pass complex objects as arguments.
You may send as many actions and arguments as you like, however, you should avoid sending too many as at some point, the header size will be exceeded. No checking is done in this regard, you are responsible for managing the size of your actions.
License
This project is distributed under the Internet Software Consortium (ISC) license: http://opensource.org/licenses/ISC