Bug 1547115 - Memoize breakableLines to avoid resetting in editor often. r=jlast

Differential Revision: https://phabricator.services.mozilla.com/D29245

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Logan Smyth 2019-04-29 21:05:15 +00:00
parent 3ba7bef4b0
commit 9d48e224c0
2 changed files with 10 additions and 4 deletions

View File

@ -6,7 +6,7 @@
import { connect } from "../../utils/connect";
import { Component } from "react";
import { getSelectedSource, getBreakableLines } from "../../selectors";
import { getSelectedSource, getSelectedBreakableLines } from "../../selectors";
import type { Source } from "../../types";
import { fromEditorLine } from "../../utils/editor";
@ -64,9 +64,7 @@ const mapStateToProps = state => {
if (!selectedSource) {
throw new Error("no selectedSource");
}
const breakableLines = new Set(
getBreakableLines(state, selectedSource.id) || []
);
const breakableLines = getSelectedBreakableLines(state);
return {
selectedSource,

View File

@ -881,4 +881,12 @@ export function getBreakableLines(state: OuterState, sourceId: string) {
return state.sources.breakableLines[sourceId];
}
export const getSelectedBreakableLines: Selector<Set<number>> = createSelector(
state => {
const sourceId = getSelectedSourceId(state);
return sourceId && state.sources.breakableLines[sourceId];
},
breakableLines => new Set(breakableLines || [])
);
export default update;