From f9521a723efefe1653e236326147d756a602c804 Mon Sep 17 00:00:00 2001 From: Flarnie Marchan Date: Sat, 3 Dec 2016 17:35:31 -0800 Subject: [PATCH] Make contentState.createFromBlockArray work with old and new API (#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. --- src/model/immutable/ContentState.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/model/immutable/ContentState.js b/src/model/immutable/ContentState.js index 8449c71d34..ff389b93aa 100644 --- a/src/model/immutable/ContentState.js +++ b/src/model/immutable/ContentState.js @@ -177,10 +177,13 @@ class ContentState extends ContentStateRecord { } static createFromBlockArray( - blocks: Array, + // TODO: update flow type when we completely deprecate the old entity API + blocks: Array | {contentBlocks: Array}, 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());