From 844b85e6576b0575a716bbfe0381336737482b53 Mon Sep 17 00:00:00 2001 From: Ian Storm Taylor Date: Wed, 13 Apr 2016 14:20:39 -0700 Subject: [PATCH] change convertFromRaw to return a ContentState, fixes #230 Summary:This way convertFromRaw and convertToRaw are parallel, both dealing with ContentState instead of one returning an array of ContentBlocks. Fixes #230. hellendag Let me know how this looks! I didn't see any tests for the converters, and I haven't used Flow before, or contributed to any Facebook repos. Closes https://github.com/facebook/draft-js/pull/239 Reviewed By: spicyj Differential Revision: D3109637 fb-gh-sync-id: 6f9cd8796c4e29eed037d22ea20de90cbe69e18f fbshipit-source-id: 6f9cd8796c4e29eed037d22ea20de90cbe69e18f --- src/model/encoding/convertFromRawToDraftState.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/model/encoding/convertFromRawToDraftState.js b/src/model/encoding/convertFromRawToDraftState.js index 2eb1f1dcbf..a48141929c 100644 --- a/src/model/encoding/convertFromRawToDraftState.js +++ b/src/model/encoding/convertFromRawToDraftState.js @@ -13,6 +13,7 @@ 'use strict'; var ContentBlock = require('ContentBlock'); +var ContentState = require('ContentState'); var DraftEntity = require('DraftEntity'); var createCharacterList = require('createCharacterList'); @@ -24,7 +25,7 @@ import type {RawDraftContentState} from 'RawDraftContentState'; function convertFromRawToDraftState( rawState: RawDraftContentState -): Array { +): ContentState { var {blocks, entityMap} = rawState; var fromStorageToLocal = {}; @@ -37,7 +38,7 @@ function convertFromRawToDraftState( } ); - return blocks.map( + var contentBlocks = blocks.map( block => { var {key, type, text, depth, inlineStyleRanges, entityRanges} = block; key = key || generateRandomKey(); @@ -60,6 +61,8 @@ function convertFromRawToDraftState( return new ContentBlock({key, type, text, depth, characterList}); } ); + + return ContentState.createFromBlockArray(contentBlocks); } module.exports = convertFromRawToDraftState;