1.0.5 • Published 4 years ago
@skripio/response-emitter v1.0.5
About
A unified way to emit responses for 1C:Enterprise platform.
Allows to generate both sync and async responses.
Installation
npm install @skripio/response-emitterUsage
- Import
ResponseEmitterclass and instantiate emitter object. Emitter will createdivelement with id provided and attach it tobodyby default. That can be changed by passingparentElementSelectorto the constructor.
import ResponseEmitter from '@skripio/response-emitter';
const re = new ResponseEmitter({
responseElementId: 'MyComponentName',
responseElementClass: 'response'
});- Call object methods to emit response message or to do auxiliary stuff.
Response
Skripio ResponseEmitter prepares and emits response message object to 1C:Enterprise platform.
Response message is guaranteed to have following structure:
{
"callback": "callback identifier",
"code": "response code",
"payload": "message payload"
}where:
- callback - contains callback identifier that allows to link function calls to responses when executing asynchronous code in
JSfrom1C:Enterprise. - code - Response code.
- payload - Message payload.
Reference
Table of Contents
ResponseEmitter
The response emitter object.
Parameters
argsobject Constructor arguments object.args.responseElementIdstring Id that will be assigned to the response DOM element.args.responseElementClass(string | Array[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)) CSS class(es) that will be assigned to the response DOM element.args.parentElementSelectorstring Selector of a DOM element that response DOM element will be attached to. (optional, default'body')
emitResponse
Generates serialized response message object. Emits click event if required.
Parameters
callbackany Any attribute to be placed against id key of the message object.codeany Any attribute to be placed against code key of the message object.payloadany Any attribute to be placed against payload key of the message object.clickboolean If truthy then click event with serialized message object will be emitted. No event emitting otherwise. (optional, defaultfalse)
Returns string Response message object serialized.
codes
ResponseEmitter.codes constants.
- DONE - 200
- RESULT - 201
- USER_ERROR - 300
- DEV_ERROR - 400
getUserMessage
ResponseEmitter.getUserMessage static method generates 1C formatted notification message from phrases in different languages.
Parameters
phrasesobject Phrases Object that contains phrases in different languages where key must be language code and value contains phrase in that language.
Examples
{
ru: 'Сообщение на Русском языке.',
en: 'Message in English language.'
}Returns string Formatted text or an empty string if object provided contains no keys with language codes listed in ISO 639-1.