question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Automatically JSON.stringify b.send

See original GitHub issue

This is just a suggestion. There’s probably some reason this doesn’t make sense but: whenever I’m using b.send to send a non-string message I want to stringify it so I end up doing e.g. b.send(JSON.stringify([message_type,[cool_data,cooler_data]])); And then obviously I end up using JSON.parse at the receiving end. Is there some reason b.send and b.on('message',... couldn’t/shouldn’t do this under the hood?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
rfestagcommented, Apr 23, 2020

I just started using this, so take my opinion with a grain of salt - but I would personally opt for configuration or some sort of middleware over growing the API for convenience functions like that. By extension, if half of people like JSON and the other half like msgpack, does the API grow to have send, sendjson, and sendmsgpack? Seems cleaner to let the user specify their preferred serialize/deserialize functions when they instantiate the Bugout instance. This would keep the API small, while still allowing people to use whatever serialization they prefer. Personally, I suspect most people will want to use JSON, so even making JSON.stringify/JSON.parse the default functions would probably be fine.

1reaction
rfestagcommented, Apr 24, 2020

Personally I never like silent anything…it would be nice to have an event emitted when something goes wrong (and I can choose whether to set up a handler for that event or not). Even if all errors were sent to the same handler (for decrypt and decode), that would be nice. For simple cases like JSON, where we can expect users to use stringify/encode, it probably isn’t a big deal. However, it could be useful when somebody does something more esoteric (say, with msgpack, if they have custom types that aren’t available at both ends for whatever reason), having the error would make debugging easier.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with JSON.stringify adding a extra \ and "" to my Json ...
It looks like you are placing a string as the value in your map. You should do something like: var objMap = {"JObject"...
Read more >
Automatic JSON stringifycation replacer parameter · Issue #2822
I'd like to have every key of my objects in the data i send to my backend, but JSON.stringify removes the properties with...
Read more >
JSON methods, toJSON - The Modern JavaScript Tutorial
The method JSON.stringify(student) takes the object and converts it into a string. The resulting json string is called a JSON-encoded or ...
Read more >
JSON.stringify() - JavaScript - MDN Web Docs
JSON.stringify() converts a value to JSON notation representing it: Boolean , Number , String , and BigInt (obtainable via Object() ) objects ...
Read more >
Converting Javascript Objects into Strings with JSON.stringify()
JSON stringification is the process of converting a Javascript object to a flat JSON string that can be used inside a program.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found