ignitionworks / draftjs_exporter

Export Draft.js content state into HTML.
MIT License
16 stars 20 forks source link

JSON data requires deep symbolization #12

Closed bramski closed 6 years ago

bramski commented 6 years ago

Kind of a nuisance. Most of the data is coming in from JSON editors and all the accessors on the data in here use symbols. If you pass deserialized JSON data into the exporter you just get a blank output. Kind of confusing.

theozaurus commented 6 years ago

Hi Bram,

JSON doesn't have the concept of a symbol key. However, when you parse your JSON you can tell it to symbolize keys.

For instance:

JSON.parse('{"key":"value"}', symbolize_names: true)
=> {:key=>"value"}

HTH

Theo

bramski commented 6 years ago

Yeah, that shouldn't be necessary when passing data to this exporter. it's really ugly to implement that way. Also, I'm pulling data in from my JSON data store, so it comes in as JSON with string keys. The code in this gem as written uses symbols to access the parts of the draftJS data structure. Requiring me to call the draftJS exporter like so:

exporter.call(draftjs_state.deep_symbolize_keys)

Not only is this an expensive operation (duplicating a big chunk of JSON), it's also quite unexpected. If you pass a JSON data structure in for your JS without turning the keys into symbols first it just completely fails to export it. That's a bug. You shouldn't have to parse the JSON with symbolized keys in order for this gem to work.

bramski commented 6 years ago

I'm not sure why you closed the issue. You basically told me a workaround. Anyone using this library should know about the fact that they have to symbolize their JSON data structure until it's fixed.