WebReflection / benja

Bootable Electron Node JS Application
https://archibold.io/benja/
194 stars 32 forks source link

JSON.parse worker data? #45

Closed lahdekorpi closed 6 years ago

lahdekorpi commented 6 years ago

https://github.com/WebReflection/benja/blob/5a4bfd00863c03dae232d65746a93a7401020368/os/qml/workers/utils.js#L6

With the demo, I'm getting an object with a data-key containing a JSON string, like: { data: '{"name":"ipv6"}'}

Should we parse the string here or is it a job if the NodeWorker?

lahdekorpi commented 6 years ago

Just to confirm, adding:


if(typeof e === "object" && e.data === "string") {
  try {
    e.data = JSON.parse(e.data);
  } catch(e) {
    console.error("Could not parse messageData", e);
  }
}

Works perfectly and the demo starts working (shows the IP address).
WebReflection commented 6 years ago

version 0.2.0 of node-worker does two things:

hope this works better for you now.