Skip to content

Commit

Permalink
Make contentState.createFromBlockArray work with old and new API (fac…
Browse files Browse the repository at this point in the history
…ebookarchive#838)

As part of the changing API the signature of
contentState.createFromBlockArray changed.

At some point (recently I think) this was changed to no longer support
the old API, and we didn't quite have the 0.9.1 style examples in place,
so it wasn't caught.

This adjusts the 'createFromBlockArray' to work with both the old and
new APIs.
  • Loading branch information
flarnie authored and ouchxp committed Apr 7, 2017
1 parent 0108853 commit f9521a7
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/model/immutable/ContentState.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ class ContentState extends ContentStateRecord {
}

static createFromBlockArray(
blocks: Array<ContentBlock>,
// TODO: update flow type when we completely deprecate the old entity API
blocks: Array<ContentBlock> | {contentBlocks: Array<ContentBlock>},
entityMap: ?any,
): ContentState {
var blockMap = BlockMapBuilder.createFromArray(blocks);
// TODO: remove this when we completely deprecate the old entity API
const theBlocks = Array.isArray(blocks) ? blocks : blocks.contentBlocks;
var blockMap = BlockMapBuilder.createFromArray(theBlocks);
var selectionState = blockMap.isEmpty()
? new SelectionState()
: SelectionState.createEmpty(blockMap.first().getKey());
Expand Down

0 comments on commit f9521a7

Please sign in to comment.