docs: Revise `clientVars` documentation

pull/5092/head
Richard Hansen 2021-06-18 22:22:56 -04:00
parent 2e2cb38225
commit f8a9cd4bad
1 changed files with 8 additions and 10 deletions

View File

@ -617,14 +617,14 @@ is sent to the client. Plugins can use this hook to manipulate the
configuration. (Example: Add a tracking ID for an external analytics tool that
is used client-side.)
The clientVars function must return a Promise that resolves to an object (or
null/undefined) whose properties will be merged into `context.clientVars`.
Returning `callback(value)` will return a Promise that is resolved to `value`.
You can modify `context.clientVars` to change the values sent to the client, but
beware: async functions from other clientVars plugins might also be reading or
manipulating the same `context.clientVars` object. For this reason it is
recommended you return an object rather than modify `context.clientVars`.
You can manipulate `clientVars` in two different ways:
* Return an object. The object will be merged into `clientVars` via
`Object.assign()`, so any keys that already exist in `clientVars` will be
overwritten by the values in the returned object.
* Modify `context.clientVars`. Beware: Other plugins might also be reading or
manipulating the same `context.clientVars` object. To avoid race conditions,
you are encouraged to return an object rather than modify
`context.clientVars`.
If needed, you can access the user's account information (if authenticated) via
`context.socket.client.request.session.user`.
@ -645,8 +645,6 @@ exports.clientVars = (hookName, context, callback) => {
};
```
This can be accessed on the client-side using `clientVars.currentYear`.
## getLineHTMLForExport
Called from: src/node/utils/ExportHtml.js