This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/js-message/js-message-vanilla.js

76 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
(
function(){
function Message() {
Object.defineProperties(
this, {
data: {
enumerable: true,
get: getData,
set: setData
},
type: {
enumerable: true,
get: getType,
set: setType
},
load:{
enumarable:true,
writable:false,
value:parse
},
JSON: {
enumerable: true,
get: getJSON
}
}
);
var type = '';
var data = {};
function getType() {
return type;
}
function getData() {
return data;
}
function getJSON() {
return JSON.stringify(
{
type: type,
data: data
}
);
}
function setType(value) {
type = value;
}
function setData(value) {
data = value;
}
function parse(message){
try{
var message=JSON.parse(message);
type=message.type;
data=message.data;
}catch(err){
var badMessage=message;
type='error',
data={
message:'Invalid JSON response format',
err:err,
response:badMessage
}
}
}
}
window.message=Message;
}
)();