-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Clean up CoffeeScript code #3651
Conversation
@@ -82,8 +81,7 @@ App.Map = | |||
e.target.bindPopup(getPopupContent(data)).openPopup() | |||
|
|||
getPopupContent = (data) -> | |||
content = "<a href='/budgets/#{data["budget_id"]}/investments/#{data["investment_id"]}'>#{data["investment_title"]}</a>" | |||
return content | |||
"<a href='/budgets/#{data["budget_id"]}/investments/#{data["investment_id"]}'>#{data["investment_title"]}</a>" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line exceeds maximum allowed length. Length is 116, max is 100.
$("#new_legislation_annotation #legislation_annotation_quote").val(@annotation.quote) | ||
$("#new_legislation_annotation #legislation_annotation_ranges").val(JSON.stringify(@annotation.ranges)) | ||
$("#new_legislation_annotation #legislation_annotation_quote").val(this.annotation.quote) | ||
$("#new_legislation_annotation #legislation_annotation_ranges").val(JSON.stringify(this.annotation.ranges)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line exceeds maximum allowed length. Length is 115, max is 100.
e1f47d8
to
4280a4b
Compare
process_background = "[name='legislation_process[background_color]']" | ||
process_font = ", [name='legislation_process[font_color]']" | ||
processes = process_background + process_font | ||
processes = "[name='legislation_process[background_color]'], [name='legislation_process[font_color]']" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line exceeds maximum allowed length. Length is 106, max is 100.
a49685e
to
d713068
Compare
d713068
to
c295528
Compare
05e5789
to
5167622
Compare
c295528
to
4e4101b
Compare
5167622
to
6dd720b
Compare
4e4101b
to
5ae1e47
Compare
6dd720b
to
bd96ea9
Compare
5ae1e47
to
1fcb1db
Compare
401189b
to
906d532
Compare
e240e98
to
febe71d
Compare
906d532
to
3634266
Compare
efe1160
to
5392646
Compare
3634266
to
49185f0
Compare
798e90b
to
de7f0d5
Compare
|
||
initialize: -> | ||
if App.WatchFormChanges.forms().length == 0 || App.WatchFormChanges.msg() == undefined | ||
return | ||
|
||
$(document).off("page:before-change").on("page:before-change", -> App.WatchFormChanges.checkChanges()) | ||
$(document).off("page:before-change").on("page:before-change", App.WatchFormChanges.checkChanges) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line exceeds maximum allowed length. Length is 101, max is 100.
7b83d79
to
eab35dc
Compare
f8ad278
to
eb277f0
Compare
There were functions which were just simple wrappers to common jQuery functions.
These methods were added in 2009 and are supported by 98.5% of the browsers, including Internet Explorer 9, 10 and 11. We were already using them in some places.
We're planning to replace CoffeeScript with JavaScript, and CoffeeScript compiles `for .. in` to complex JavaScript code.
The code won't do anything if there are no elements, so there's no need to check that condition.
The `append` method can handle arrays, so there's no need to loop through each element. There's more to improve on this method, like the `asc` variable being global to a table instead of depending on the current column, but for now I'm only refactoring and maintaining the current behaviour.
Including the table body is more intuitive than excluding the first row and the table foot.
Using the same name means from that point the name doesn't refer to the original parameter, which might be confusing when reading the method.
Iterating through the jQuery elements with `each` is more similar to other iterators we use. Furthermore, we avoid declaring the `index` variable we don't use.
Combining both the inline and "traditional" `if` styles made the code difficult to read, particularly when compiled to JavaScript.
In foundation extras we were assigning functions to local variables, but in the rest of the CoffeeScript files we use them as object properties.
We're using `this` most of the time, and it's what's used in JavaScript.
Strict mode is supported by 98% of the browsers, including Internet Explorer 10, and it helps developers avoid common JavaScript pitfalls.
The assignment operator can easily be mistaken with the equality operator when used in a condition, making the code more difficult to read.
In JavaScript we cannot easily repeat something N times, and CoffeeScript's range loop compiles into complex JavaScript. We could also use `Array.from({ length: N })`, but that's not supported by old browsers like Internet Explorer 11.
Local variables are one of the things CoffeeScript doesn't compile to modern JavaScript automatically: it uses `var` instead of `const` or `let`. Besides, using `$this = $(this)` is usually done to reference the current object in another function where the current object is a different one. Here we were using it with no clear purpose.
We accidentally added some single quotes recently.
eb277f0
to
d8be18d
Compare
…ript Clean up CoffeeScript code
References
Background
We're planning to convert all our CoffeeScript code to JavaScript. As a first step, this pull request cleans some of the CoffeeScript code up, and rewrites the parts which would generate complex JavaScript code.
Objectives