-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(performance): changes to improve performance
I believe there are two aspects that affected the performance of JNS since v1.6.3 - one was the mutations. This has been 'improved' by introducing a set object to make sure event listeners are not added to existing nodes. Another improvement was to refactor out the parentNode call before building the array of WarningHighlights.
- Loading branch information
James Duffy
committed
Feb 17, 2021
1 parent
3d1e32a
commit bca3ac9
Showing
10 changed files
with
181 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { findRanges } from '../src/helpers/RangeFinder'; | ||
|
||
describe('RangeFinder', () => { | ||
const PHRASE_TO_FIND = { | ||
regex: new RegExp('textToFind', 'ig'), | ||
message: 'text found!', | ||
}; | ||
let element; | ||
beforeEach(() => { | ||
element = document.createElement('div'); | ||
}); | ||
it('should return empty array if given empty array', () => { | ||
const ranges = findRanges(element, []); | ||
expect(ranges.length).toBe(0); | ||
}); | ||
|
||
it('should return array with message and valid range for each match found', () => { | ||
element.textContent = 'textToFind'; | ||
|
||
const ranges = findRanges(element, [PHRASE_TO_FIND]); | ||
|
||
expect(ranges.length).toBe(1); | ||
expect(ranges).toEqual([ | ||
{ message: 'text found!', rangeToHighlight: new Range() }, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
const isEmailMessageBody = (mutation) => | ||
mutation.type === 'childList' && | ||
mutation.target.hasAttribute('contentEditable'); | ||
|
||
export const ifEmailModified = (action) => (mutations) => { | ||
const index = mutations.findIndex(isEmailMessageBody); | ||
if (index > -1) { | ||
action(mutations[index]); | ||
} | ||
function isEmailMessageBody(mutation) { | ||
return ( | ||
mutation.type === 'childList' && | ||
mutation.target.hasAttribute('contentEditable') | ||
); | ||
} | ||
export const forEachUniqueContentEditable = (action) => { | ||
const uniqueIds = new Set(); | ||
return (mutations) => { | ||
mutations.filter(isEmailMessageBody).forEach((mutation) => { | ||
if (!uniqueIds.has(mutation.target.id)) { | ||
const id = mutation.target.id; | ||
uniqueIds.add(id); | ||
action(mutation); | ||
} | ||
}); | ||
}; | ||
}; |
Oops, something went wrong.