Skip to content

Latest commit

 

History

History
80 lines (59 loc) · 1.63 KB

SliceMessage.markdown

File metadata and controls

80 lines (59 loc) · 1.63 KB

SliceMessage

Message class, stores message name and data. The one that is transportend.

constructor(name, data)

SliceMessage constructor

Example:
const myMessage = new SliceMessage('message', {
    variable1: 'value1',
    variable2: 'value2',
    variableN: 'valueN'
});

Properties

Name Type Description
name string Message name
data variable Message data

Methods

toString()

Converts SliceMessage message object to string.

Example:
const myMessage = SliceMessage.create('message', {
    variable1: 'value1',
    variable2: 'value2',
    variableN: 'valueN'
});

const myMessageString = myMessage.toString();
// '{"name": "Message name","data": {"variable1": "value1","variable2": "value2","variableN": "valueN"}}'

Static methods

static create(name, data)

Creates new SliceMessage with provided name and data.

Example:
const myMessage = SliceMessage.create('message', {
    variable1: 'value1',
    variable2: 'value2',
    variableN: 'valueN'
});
static fromJSON(str)

Parses str and creates new SliceMessage.
str should be in JSON format, like:

{
    "name": "Message name",
    "data": {
        "variable1": "value1",
        "variable2": "value2",
        "variableN": "valueN"
    }
}
Example:
const myJSON = '{"name": "Message name","data": {"variable1": "value1","variable2": "value2","variableN": "valueN"}}';
const myMessage = SliceMessage.fromJSON(myJSON);