ericadamski / collaborative-edit

A collaboration package for the Atom Text Editor ( REMOVED FROM ATOM, for now, due to many errors )
MIT License
2 stars 1 forks source link

Use common CoffeeScript function patterns #9

Open Sieniawsky opened 9 years ago

Sieniawsky commented 9 years ago

Currently, a lot of the code base uses excessive parenthesis. By design CoffeeScript does not require parenthesis when invoking a function, unless the function takes no arguments, or some post-fix operators are used. Additionally, function signatures should conform with following pattern:

  foo = (data, done) ->
      #do something

Where data could be any number of parameters and done is the top-level callback.

For example the code here can be simplified:

This:

  synchId = setInterval(
      (-> remote.synchronize(shareJsDocContext)),
      NO_OP_TIMEOUT
  )

Becomes this with the (data, done) pattern and reduced parenthesis:

  synchId = setInterval NO_OP_TIMEOUT, -> remote.synchronize shareJsDocContext
ericadamski commented 9 years ago

data being an object?

Sieniawsky commented 9 years ago

Data is just an example, but there could be more than one if needed such as:

  foo = (data, data2, options, done) ->
       # do something
ericadamski commented 9 years ago

I understand this convention, but I have no use for callbacks in most of the functions I have written thus far, maybe further on into the project a refactoring can be done to make the code more JS/CoffeeScript friendly