1.0.5 • Published 2 years ago

@skripio/response-emitter v1.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

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

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.

1.0.5

2 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago