Skip to content

Commit

Permalink
fix: new DecorationSet() -> DecorationSet.empty
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathonherbert committed Jan 28, 2021
1 parent 67c1037 commit 91963eb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/ts/state/helpers.ts
Expand Up @@ -20,7 +20,7 @@ export const addMatchesToState = <TPluginState extends IPluginState>(
const matchesToApply = matches.filter(match => !ignoreMatch(match));
const decorations = matchesToApply.reduce(
(set, output) => set.add(doc, createDecorationsForMatch(output)),
new DecorationSet()
DecorationSet.empty
);
return {
...state,
Expand Down
6 changes: 3 additions & 3 deletions src/ts/state/test/helpers.spec.ts
Expand Up @@ -82,7 +82,7 @@ describe("State helpers", () => {
filterByMatchState
);
expect(filteredMatches).toEqual([]);
expect(decorations).toEqual(new DecorationSet());
expect(decorations).toEqual(DecorationSet.empty);
});
it("should handle a no-op filter state, adding matches to the filtered state", () => {
const matches = [createMatch(1, 4), createMatch(4, 7)];
Expand All @@ -98,7 +98,7 @@ describe("State helpers", () => {
);
expect(filteredMatches).toEqual(currentMatches);
expect(decorations).toEqual(
getNewDecorationsForCurrentMatches(matches, new DecorationSet(), tr.doc)
getNewDecorationsForCurrentMatches(matches, DecorationSet.empty, tr.doc)
);
});
it("should remove matches when they don't pass the filter", () => {
Expand All @@ -116,7 +116,7 @@ describe("State helpers", () => {

expect(currentMatches).toEqual(matches);
expect(filteredMatches).toEqual([]);
expect(decorations).toEqual(new DecorationSet());
expect(decorations).toEqual(DecorationSet.empty);
});
});
});
24 changes: 12 additions & 12 deletions src/ts/state/test/reducer.spec.ts
Expand Up @@ -96,7 +96,7 @@ describe("Action handlers", () => {
debug: true
},
dirtiedRanges: [],
decorations: new DecorationSet().add(tr.doc, [
decorations: DecorationSet.empty.add(tr.doc, [
createDebugDecorationFromRange({ from: 1, to: 22 }, false)
]),
requestPending: false,
Expand All @@ -119,15 +119,15 @@ describe("Action handlers", () => {
...state,
config: { ...state.config, debug: true },
dirtiedRanges: [{ from: 5, to: 10 }],
decorations: new DecorationSet().add(tr.doc, [
decorations: DecorationSet.empty.add(tr.doc, [
createDebugDecorationFromRange({ from: 1, to: 3 })
]),
requestPending: true
},
requestMatchesForDirtyRanges("id", exampleCategoryIds)
);
expect(newState.decorations).toEqual(
new DecorationSet().add(tr.doc, [
DecorationSet.empty.add(tr.doc, [
createDebugDecorationFromRange({ from: 1, to: 22 }, false)
])
);
Expand All @@ -147,7 +147,7 @@ describe("Action handlers", () => {
{ from: 5, to: 10 },
{ from: 28, to: 35 }
],
decorations: new DecorationSet(),
decorations: DecorationSet.empty,
requestPending: true
},
requestMatchesForDirtyRanges("id", exampleCategoryIds)
Expand Down Expand Up @@ -219,7 +219,7 @@ describe("Action handlers", () => {
requestMatchesSuccess(createMatcherResponse([{ from: 5, to: 10 }]))
);
const newMatch = newState.currentMatches[0];
const newDecorations = new DecorationSet().add(
const newDecorations = DecorationSet.empty.add(
tr.doc,
createDecorationsForMatch(newMatch)
);
Expand Down Expand Up @@ -278,7 +278,7 @@ describe("Action handlers", () => {
);

expect(newState.decorations).toEqual(
new DecorationSet().add(tr.doc, [
DecorationSet.empty.add(tr.doc, [
...createDecorationsForMatch(matcherResponse2.matches[0]),
...createDecorationsForMatch(matcherResponse3.matches[0])
])
Expand Down Expand Up @@ -384,7 +384,7 @@ describe("Action handlers", () => {
const currentMatches = matches.slice(0, 1);
const decorations = getNewDecorationsForCurrentMatches(
currentMatches,
new DecorationSet(),
DecorationSet.empty,
defaultDoc
);

Expand Down Expand Up @@ -425,7 +425,7 @@ describe("Action handlers", () => {
to: 25
}
],
decorations: new DecorationSet(),
decorations: DecorationSet.empty,
requestErrors: [
{
requestId: exampleRequestId,
Expand Down Expand Up @@ -507,14 +507,14 @@ describe("Action handlers", () => {
const localState = {
...state,
currentMatches: [output],
decorations: new DecorationSet().add(
decorations: DecorationSet.empty.add(
tr.doc,
createDecorationsForMatch(output, defaultMatchColours, false)
)
};
expect(reducer(tr, localState, newHoverIdReceived("match-id", 1))).toEqual({
...localState,
decorations: new DecorationSet().add(
decorations: DecorationSet.empty.add(
tr.doc,
createDecorationsForMatch(output, defaultMatchColours, true)
),
Expand Down Expand Up @@ -544,7 +544,7 @@ describe("Action handlers", () => {
};
const localState = {
...state,
decorations: new DecorationSet().add(tr.doc, [
decorations: DecorationSet.empty.add(tr.doc, [
...createDecorationsForMatch(output, defaultMatchColours, true)
]),
currentMatches: [output],
Expand All @@ -555,7 +555,7 @@ describe("Action handlers", () => {
reducer(tr, localState, newHoverIdReceived(undefined, undefined))
).toEqual({
...localState,
decorations: new DecorationSet().add(tr.doc, [
decorations: DecorationSet.empty.add(tr.doc, [
...createDecorationsForMatch(output, defaultMatchColours, false)
]),
hoverId: undefined,
Expand Down
2 changes: 1 addition & 1 deletion src/ts/test/helpers/prosemirror.ts
Expand Up @@ -35,7 +35,7 @@ export const getDecorationSpecsFromDoc = (
getDecorationSpecsFromSet(view.someProp("decorations", f => f(view.state)));

export const getDecorationSpecsFromMatches = (matches: IMatch[], doc: Node) => {
const decorationSet = getNewDecorationsForCurrentMatches(matches, new DecorationSet(), doc)
const decorationSet = getNewDecorationsForCurrentMatches(matches, DecorationSet.empty, doc)
return getDecorationSpecsFromSet(decorationSet);
}

Expand Down

0 comments on commit 91963eb

Please sign in to comment.