Skip to content

Commit

Permalink
Fix 0.10 compatibility break in getDecorations (facebookarchive#860)
Browse files Browse the repository at this point in the history
  • Loading branch information
colinjeanne authored and ouchxp committed Apr 7, 2017
1 parent 7d12829 commit 5096b59
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/model/decorators/CompositeDraftDecorator.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CompositeDraftDecorator {
this._decorators = decorators.slice();
}

getDecorations(contentState: ContentState, block: ContentBlock): List<?string> {
getDecorations(block: ContentBlock, contentState: ContentState): List<?string> {
var decorations = Array(block.getText().length).fill(null);

this._decorators.forEach(
Expand Down
2 changes: 1 addition & 1 deletion src/model/decorators/DraftDecoratorType.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type DraftDecoratorType = {
/**
* Given a `ContentBlock`, return an immutable List of decorator keys.
*/
getDecorations(contentState: ContentState, block: ContentBlock): List<?string>,
getDecorations(block: ContentBlock, contentState: ContentState): List<?string>,

/**
* Given a decorator key, return the component to use when rendering
Expand Down
14 changes: 7 additions & 7 deletions src/model/decorators/__tests__/CompositeDraftDecorator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('CompositeDraftDecorator', () => {
var text = 'take a sad song and make it better';
var content = new ContentBlock(text);
var contentState = ContentState.createFromText(text);
var decorations = composite.getDecorations(contentState, content).toArray();
var decorations = composite.getDecorations(content, contentState).toArray();
expect(decorations.length).toBe(text.length);
expect(decorations).toEqual(Array(text.length).fill(null));
});
Expand All @@ -93,7 +93,7 @@ describe('CompositeDraftDecorator', () => {
var text = 'a footballing fool';
var content = new ContentBlock(text);
var contentState = ContentState.createFromText(text);
var decorations = composite.getDecorations(contentState, content).toArray();
var decorations = composite.getDecorations(content, contentState).toArray();
expect(decorations.length).toBe(text.length);

expect(isOccupied(decorations.slice(2, 5))).toBe(true);
Expand All @@ -112,7 +112,7 @@ describe('CompositeDraftDecorator', () => {
var text = 'a foosball bar';
var content = new ContentBlock(text);
var contentState = ContentState.createFromText(text);
var decorations = composite.getDecorations(contentState, content).toArray();
var decorations = composite.getDecorations(content, contentState).toArray();

// Match the "Foo" decorator.
expect(isOccupied(decorations.slice(2, 5))).toBe(true);
Expand All @@ -134,7 +134,7 @@ describe('CompositeDraftDecorator', () => {
var text = 'some bar food';
var content = new ContentBlock(text);
var contentState = ContentState.createFromText(text);
var decorations = composite.getDecorations(contentState, content).toArray();
var decorations = composite.getDecorations(content, contentState).toArray();

// Match the "Foo" decorator.
expect(isOccupied(decorations.slice(9, 12))).toBe(true);
Expand All @@ -154,7 +154,7 @@ describe('CompositeDraftDecorator', () => {
var text = 'bart has a bar';
var content = new ContentBlock(text);
var contentState = ContentState.createFromText(text);
var decorations = composite.getDecorations(contentState, content).toArray();
var decorations = composite.getDecorations(content, contentState).toArray();

// Even though "bart" matches our "bar" strategy, "bart" comes first
// in our decoration order and will claim those letters first.
Expand All @@ -179,7 +179,7 @@ describe('CompositeDraftDecorator', () => {
var text = 'bart has a bar';
var content = new ContentBlock(text);
var contentState = ContentState.createFromText(text);
var decorations = composite.getDecorations(contentState, content).toArray();
var decorations = composite.getDecorations(content, contentState).toArray();

// "bar" comes first and claims two strings.
expect(isOccupied(decorations.slice(0, 3))).toBe(true);
Expand All @@ -202,7 +202,7 @@ describe('CompositeDraftDecorator', () => {
var text = 'barbarbar';
var content = new ContentBlock(text);
var contentState = ContentState.createFromText(text);
var decorations = composite.getDecorations(contentState, content).toArray();
var decorations = composite.getDecorations(content, contentState).toArray();

expect(isOccupied(decorations.slice(0, 3))).toBe(true);
expect(decorations[0]).toEqual(decorations[2]);
Expand Down
2 changes: 1 addition & 1 deletion src/model/immutable/BlockTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var BlockTree = {

var leafSets = [];
var decorations = decorator ?
decorator.getDecorations(contentState, block) :
decorator.getDecorations(block, contentState) :
List(Repeat(null, textLength));

var chars = block.getCharacterList();
Expand Down
4 changes: 2 additions & 2 deletions src/model/immutable/EditorState.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@ function regenerateTreeForNewDecorator(
.toSeq()
.filter(block => {
return (
decorator.getDecorations(content, block) !==
existingDecorator.getDecorations(content, block)
decorator.getDecorations(block, content) !==
existingDecorator.getDecorations(block, content)
);
})
.map(block => BlockTree.generate(content, block, decorator)),
Expand Down
6 changes: 3 additions & 3 deletions src/model/immutable/__tests__/EditorState-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe('EditorState', () => {

beforeEach(() => {
Decorator.prototype.getDecorations.mockClear();
Decorator.prototype.getDecorations.mockImplementation((c, v) => {
Decorator.prototype.getDecorations.mockImplementation((v, c) => {
return v === boldBlock ? boldA : List(Repeat(undefined, v.getLength()));
});
});
Expand All @@ -236,11 +236,11 @@ describe('EditorState', () => {
var editorState = getDecoratedEditorState(decorator);
expect(decorator.getDecorations.mock.calls.length).toBe(2);

Decorator.prototype.getDecorations.mockImplementation((c, v) => {
Decorator.prototype.getDecorations.mockImplementation((v, c) => {
return v === boldBlock ? boldB : List(Repeat(undefined, v.getLength()));
});
var newDecorator = new NextDecorator();
NextDecorator.prototype.getDecorations.mockImplementation((c, v) => {
NextDecorator.prototype.getDecorations.mockImplementation((v, c) => {
return v === boldBlock ? boldB : List(Repeat(undefined, v.getLength()));
});

Expand Down

0 comments on commit 5096b59

Please # to comment.