Skip to content
This repository has been archived by the owner on Feb 6, 2023. It is now read-only.

Commit

Permalink
change convertFromRaw to return a ContentState, fixes #230
Browse files Browse the repository at this point in the history
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 #239

Reviewed By: spicyj

Differential Revision: D3109637

fb-gh-sync-id: 6f9cd8796c4e29eed037d22ea20de90cbe69e18f
fbshipit-source-id: 6f9cd8796c4e29eed037d22ea20de90cbe69e18f
  • Loading branch information
ianstormtaylor authored and Facebook Github Bot 4 committed Apr 13, 2016
1 parent ed54d81 commit 844b85e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/model/encoding/convertFromRawToDraftState.js
Expand Up @@ -13,6 +13,7 @@
'use strict';

var ContentBlock = require('ContentBlock');
var ContentState = require('ContentState');
var DraftEntity = require('DraftEntity');

var createCharacterList = require('createCharacterList');
Expand All @@ -24,7 +25,7 @@ import type {RawDraftContentState} from 'RawDraftContentState';

function convertFromRawToDraftState(
rawState: RawDraftContentState
): Array<ContentBlock> {
): ContentState {
var {blocks, entityMap} = rawState;

var fromStorageToLocal = {};
Expand All @@ -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();
Expand All @@ -60,6 +61,8 @@ function convertFromRawToDraftState(
return new ContentBlock({key, type, text, depth, characterList});
}
);

return ContentState.createFromBlockArray(contentBlocks);
}

module.exports = convertFromRawToDraftState;

0 comments on commit 844b85e

Please sign in to comment.