Draft-js: convertToRaw and convertFromRaw not quite parallel

Created on 24 Mar 2016  路  2Comments  路  Source: facebook/draft-js

Hey, first off let me just say thanks for the awesome library! Currently getting familiar with it, and implementing HTML parsing to be able to store content as HTML in the database, but use Draft as the editor. Love the concept of it.

I noticed that convertToRaw and convertFromRaw aren't quite parallel, and I was wondering why? convertFromRaw returns an array of ContentBlocks that you have to convert into a ContentState yourself, and convertToRaw takes a fully-formed ContentState.

It seems like it would be nicer for consistency if convertFromRaw returned a ContentState instead of an array of ContentBlocks. (Or vice versa if there's a reason for wanting the lower-level array of blocks.)

enhancement

Most helpful comment

You're absolutely right, it's an odd asymmetry.

I don't think I made the decision intentionally, it just turned out that way. I was probably thinking I'd want to have flexibility with selectionBefore and selectionAfter within convertFromRaw, but in practice I doubt anything was really ever gained.

convertFromRaw should probably be changed to return a full ContentState. It would be a breaking change, but it would nicely eliminate the need to use ContentState.createFromBlockArray all the time.

All 2 comments

You're absolutely right, it's an odd asymmetry.

I don't think I made the decision intentionally, it just turned out that way. I was probably thinking I'd want to have flexibility with selectionBefore and selectionAfter within convertFromRaw, but in practice I doubt anything was really ever gained.

convertFromRaw should probably be changed to return a full ContentState. It would be a breaking change, but it would nicely eliminate the need to use ContentState.createFromBlockArray all the time.

Would you like to submit a PR for this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mvnnn picture mvnnn  路  3Comments

ufo22940268 picture ufo22940268  路  3Comments

jackmatrix picture jackmatrix  路  3Comments

roundrobin picture roundrobin  路  3Comments

pklavins picture pklavins  路  3Comments