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

Commit 96e7f25

Browse files
Frank Thompsonfacebook-github-bot
authored andcommitted
Revert D16362778: [rfc][draftjs] catch errors when encoding entity map
Differential Revision: D16362778 Original commit changeset: 6e2a6041d1a0 fbshipit-source-id: 9c0e3f2c1033c8f6879e03ce4cf8799fab5e0a02
1 parent c0e911c commit 96e7f25

File tree

3 files changed

+14
-55
lines changed

3 files changed

+14
-55
lines changed

src/model/encoding/__tests__/__snapshots__/convertFromDraftStateToRaw-test.js.snap

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`must be able to convert from draft state entities not in map 1`] = `
4-
Object {
5-
"blocks": Array [
6-
Object {
7-
"data": Object {},
8-
"depth": 0,
9-
"entityRanges": Array [
10-
Object {
11-
"key": 0,
12-
"length": 7,
13-
"offset": 0,
14-
},
15-
],
16-
"inlineStyleRanges": Array [],
17-
"key": "a",
18-
"text": "badlink",
19-
"type": "unstyled",
20-
},
21-
],
22-
"entityMap": Object {},
23-
}
24-
`;
25-
263
exports[`must be able to convert from draft state with ContentBlock to raw 1`] = `
274
Object {
285
"blocks": Array [

src/model/encoding/__tests__/convertFromDraftStateToRaw-test.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const treeContentState = contentState.set(
6161
]),
6262
);
6363

64-
const getMetadata = (entityKey, length) =>
65-
Immutable.Repeat(CharacterMetadata.create({entity: entityKey}), length);
64+
const getMetadata = entityKey =>
65+
Immutable.Repeat(CharacterMetadata.create({entity: entityKey}), 5);
6666
const getLink = entityKey =>
6767
new DraftEntityInstance({
6868
type: 'LINK',
@@ -79,23 +79,23 @@ const contentStateWithNonContiguousEntities = ContentState.createFromBlockArray(
7979
key: 'a',
8080
type: 'unstyled',
8181
text: 'link2 link2 link3',
82-
characterList: getMetadata('2', 5)
82+
characterList: getMetadata('2')
8383
.toList()
8484
.push(CharacterMetadata.EMPTY)
85-
.concat(getMetadata('2', 5))
85+
.concat(getMetadata('2'))
8686
.push(CharacterMetadata.EMPTY)
87-
.concat(getMetadata('3', 5)),
87+
.concat(getMetadata('3')),
8888
}),
8989
new ContentBlock({
9090
key: 'b',
9191
type: 'unstyled',
9292
text: 'link4 link2 link5',
93-
characterList: getMetadata('4', 5)
93+
characterList: getMetadata('4')
9494
.toList()
9595
.push(CharacterMetadata.EMPTY)
96-
.concat(getMetadata('2', 5))
96+
.concat(getMetadata('2'))
9797
.push(CharacterMetadata.EMPTY)
98-
.concat(getMetadata('5', 5)),
98+
.concat(getMetadata('5')),
9999
}),
100100
],
101101
)
@@ -104,15 +104,6 @@ const contentStateWithNonContiguousEntities = ContentState.createFromBlockArray(
104104
.addEntity(getLink('4'))
105105
.addEntity(getLink('5'));
106106

107-
const contentStateWithEntitiesNotInMap = ContentState.createFromBlockArray([
108-
new ContentBlock({
109-
key: 'a',
110-
type: 'unstyled',
111-
text: 'badlink',
112-
characterList: getMetadata('999', 7).toList(),
113-
}),
114-
]);
115-
116107
const assertConvertFromDraftStateToRaw = content => {
117108
expect(convertFromDraftStateToRaw(content)).toMatchSnapshot();
118109
};
@@ -128,7 +119,3 @@ test('must be able to convert from draft state with ContentBlockNode to raw', ()
128119
test('must be able to convert from draft state with noncontiguous entities to raw', () => {
129120
assertConvertFromDraftStateToRaw(contentStateWithNonContiguousEntities);
130121
});
131-
132-
test('must be able to convert from draft state entities not in map', () => {
133-
assertConvertFromDraftStateToRaw(contentStateWithEntitiesNotInMap);
134-
});

src/model/encoding/convertFromDraftStateToRaw.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import type {RawDraftContentState} from 'RawDraftContentState';
1919
const ContentBlock = require('ContentBlock');
2020
const ContentBlockNode = require('ContentBlockNode');
2121
const DraftStringKey = require('DraftStringKey');
22-
const FBLogger = require('FBLogger');
2322

2423
const encodeEntityRanges = require('encodeEntityRanges');
2524
const encodeInlineStyleRanges = require('encodeInlineStyleRanges');
@@ -118,16 +117,12 @@ const encodeRawEntityMap = (
118117
const rawEntityMap = {};
119118

120119
Object.keys(entityMap).forEach((key, index) => {
121-
try {
122-
const entity = contentState.getEntity(DraftStringKey.unstringify(key));
123-
rawEntityMap[index] = {
124-
type: entity.getType(),
125-
mutability: entity.getMutability(),
126-
data: entity.getData(),
127-
};
128-
} catch (e) {
129-
FBLogger('draft-js-contrib').catching(e);
130-
}
120+
const entity = contentState.getEntity(DraftStringKey.unstringify(key));
121+
rawEntityMap[index] = {
122+
type: entity.getType(),
123+
mutability: entity.getMutability(),
124+
data: entity.getData(),
125+
};
131126
});
132127

133128
return {

0 commit comments

Comments
 (0)