Skip to content

Commit

Permalink
fix: moved data in to object
Browse files Browse the repository at this point in the history
  • Loading branch information
frankpagan committed Dec 25, 2024
1 parent 5102f60 commit 168bb0a
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ const CoCreateApi = {
(!object.event && object.type === "action") ||
(object.event && object.event.includes(object.type))
) {
let data = await CoCreateApi.getData(object);
if (Object.keys(data).length) CoCreateApi.send(object, data);
object.data = await CoCreateApi.getData(object);
if (Object.keys(object.data).length) CoCreateApi.send(object);
}
},

response: function (object, data) {
response: function (object) {
const name = object.name;
const method = object.method;
const data = object.data;
if (this.modules[name][method] && this.modules[name][method].response)
this.modules[name][method].response(data[name]);
else if (data.error) {
Expand All @@ -126,33 +127,34 @@ const CoCreateApi = {
]
});
} else {
CoCreateApi.setData(object, data);
CoCreateApi.setData(object);

document.dispatchEvent(
new CustomEvent(object.endEvent, {
detail: {
data: data[name]
data: object
}
})
);
}
},

send: async function (object, data) {
data = await Socket.send({
send: async function (object) {
object.data = await Socket.send({
method: object.name + "." + object.method,
[object.name]: data,
[object.name]: object.data,
broadcast: false,
broadcastBrowser: false,
status: "await"
});
this.response(object, data);
this.response(object);
},

getData: async function ({ name, method, element, form }) {
let data = {};

if (!form && element) form = element.closest("form");
if (!form) form = document;

let elements;
if (form)
Expand Down Expand Up @@ -204,8 +206,9 @@ const CoCreateApi = {
return data;
},

setData: function (object, data) {
setData: function (object) {
const name = object.name;
const data = object.data;
let form = object.form;
if (!form) form = document;

Expand Down

0 comments on commit 168bb0a

Please sign in to comment.