@skripio/response-emitter

1.0.5 • Public • Published

js-semistandard-style Conventional Commits

About

A unified way to emit responses for 1C:Enterprise platform.

Allows to generate both sync and async responses.

Installation

npm install @skripio/response-emitter

Usage

  1. Import ResponseEmitter class and instantiate emitter object. Emitter will create div element with id provided and attach it to body by default. That can be changed by passing parentElementSelector to the constructor.
    import ResponseEmitter from '@skripio/response-emitter';
    const re = new ResponseEmitter({
        responseElementId: 'MyComponentName', 
        responseElementClass: 'response'
        });
  1. 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 JS from 1C:Enterprise.
  • code - Response code.
  • payload - Message payload.

Reference

Table of Contents

ResponseEmitter

The response emitter object.

Parameters

  • args object Constructor arguments object.

    • args.responseElementId string Id that will be assigned to the response DOM element.
    • args.responseElementClass (string | Array<string>) CSS class(es) that will be assigned to the response DOM element.
    • args.parentElementSelector string 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

  • callback any Any attribute to be placed against id key of the message object.
  • code any Any attribute to be placed against code key of the message object.
  • payload any Any attribute to be placed against payload key of the message object.
  • click boolean If truthy then click event with serialized message object will be emitted. No event emitting otherwise. (optional, default false)

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

  • phrases object 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.

Readme

Keywords

Package Sidebar

Install

npm i @skripio/response-emitter

Weekly Downloads

1

Version

1.0.5

License

ISC

Unpacked Size

31.4 kB

Total Files

7

Last publish

Collaborators

  • a6848418