Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update spellcheck API in smoketest #116

Merged
merged 3 commits into from Sep 24, 2018
Merged

Conversation

nitsakh
Copy link
Contributor

@nitsakh nitsakh commented Sep 20, 2018

Updates the spellcheck API in smoke tests.
[Corresponding electron change https://github.com/electron/electron/pull/14032]

@MarshallOfSound
Copy link
Member

You'll need to update the docs hash for the tests to pass

https://github.com/electron/electron-typescript-definitions/blob/master/vendor/fetch-docs.jsL

You can point it at your PR

@zeke
Copy link
Contributor

zeke commented Sep 20, 2018

🤘

webFrame.setSpellCheckProvider('en-US', {
spellCheck (words, callback) {
setTimeout(() => {
let misspeltWords = []
Copy link
Member

@ckerr ckerr Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • nit: `misspelt' is valid but has 1/28th the Google hits as 'misspelled', and the spellchecker API uses the word 'misspelled', so let's follow the Principle of Least Surprise and use it here too
  • const in JS means "we won't change the address this pointer points to" rather than "this variable's value is immutable", so this can & should be const rather than let

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually using misspelt in the updated spellcheck API PR in electron. Changed that also.

setTimeout(() => {
let misspeltWords = []
for (let word of words) {
if (require('spellchecker').isMisspelled(word)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • require() has a nontrivial cost, so it's better to move it outside of this loop into a local const
  • Array.prototype.filter() would be useful here

misspeltWords.push(word)
}
}
callback(misspeltWords)
Copy link
Member

@ckerr ckerr Sep 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more concise:

const spellchecker = require('spellchecker')
const misspelled = words.filter(x => spellchecker.isMisspelled(x))
callback(misspelled)

@nitsakh
Copy link
Contributor Author

nitsakh commented Sep 23, 2018

Thanks for the feedback @ckerr ! 🙇

spellCheck (words, callback) {
setTimeout(() => {
const spellchecker = require('spellchecker')
const misspelled = words.filter(x => spellchecker.isMisspelled(x))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know misspelt is "a word", but I'm glad to see that it got refactored away. 😛

@MarshallOfSound MarshallOfSound merged commit b1e69e1 into master Sep 24, 2018
@MarshallOfSound MarshallOfSound deleted the update-spellAPI branch September 24, 2018 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants