fixing toJSON when called by JSON.stringify #11

Merged
saranrapjs merged 1 commit from fix-tojson into master 2018-01-22 17:40:28 +01:00
saranrapjs commented 2018-01-19 18:08:22 +01:00 (Migrated from github.com)

This fixes an error that can be thrown if you try to stringify the EditorState inside of parent object. Per the JSON.stringify docs:

the value returned by the toJSON() method when called will be serialized. JSON.stringify() calls toJSON with one parameter:

  • if this object is a property value, the property name
  • if it is in an array, the index in the array, as a string
  • an empty string if JSON.stringify() was directly called on this object

This allows the status quo pluginFields behavior, while still being compatible w/ JSON.stringify.

This fixes an error that can be thrown if you try to stringify the EditorState inside of parent object. Per the [JSON.stringify docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#toJSON()_behavior): > the value returned by the toJSON() method when called will be serialized. JSON.stringify() calls toJSON with one parameter: > - if this object is a property value, the property name > - if it is in an array, the index in the array, as a string > - an empty string if JSON.stringify() was directly called on this object This allows the status quo `pluginFields` behavior, while still being compatible w/ `JSON.stringify`.
marijnh commented 2018-01-22 17:41:48 +01:00 (Migrated from github.com)

That's reasonable. I've clarified the docs a bit in b6f935e9b7 and merged this.

That's reasonable. I've clarified the docs a bit in b6f935e9b7 and merged this.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
prosemirror/prosemirror-state!11
No description provided.