Right now code-manager.js uses store.editor implicitly. This makes bugs like #669 a lot likelier since a user of the function may not check if store.editor !== null beforehand.
If we move to pure functions this will become more transparent and we can even add flow to this file to be reminded every time we don't check for the case store.editor == null before using a function.
For example getTextInRange right now looks like this (the output depends on the value of store.editor):
export function getTextInRange(start, end) {
const code = store.editor.getTextInBufferRange([start, end]);
return normalizeString(code);
}
As a pure functions and with flow typings it would look like this (the output only depends on the input parameters):
/* @flow */
export function getTextInRange(editor: atom$TextEditor, start: atom$Point, end: atom$Point) {
const code = editor.getTextInBufferRange([start, end]);
return normalizeString(code);
}
brb... reading up on flow
At first glance it looks similar to julia types, one of the reasons julia is probably my favorite language.
Nice, and they even have a cool new website, just in time 馃槅 https://flowtype.org/
I'm going to take a crack at this after work today.
@BenRussert Very cool! 馃帀
There will be likely a few flow errors due to missing declarations so feel free to submit a work in progress PR.
PS: If you need a nice flow linter I recommend the flow-ide plugin.
PS: If you need a nice flow linter I recommend the flow-ide plugin.
Cool, I was going to ask about this. Tried Nuclide, but it was a little much for me at this point.
@lgeiger this is going pretty well so far. You were right that the stopping point was type declarations.
Is the plan just to add to the atom.js.flow file as we go? There were several missing methods/properties under atom$TextEditor and atom$TextBuffer that I could add to the file.
Great!
Is the plan just to add to the atom.js.flow file as we go? There were several missing methods/properties under atom$TextEditor and atom$TextBuffer that I could add to the file.
馃憤 That's what I've been doing so far
This is working and passing tests (though I had to alter the code manger spec. I'll pr tomorrow for some feedback.
https://github.com/BenRussert/hydrogen/tree/refactor-cm-flow
Most helpful comment
Cool, I was going to ask about this. Tried Nuclide, but it was a little much for me at this point.