kakajansh / flowwy

Boilerplate app that integrates Meteor + Famo.us + FlowRouter
2 stars 2 forks source link

coding style #8

Open dcsan opened 9 years ago

dcsan commented 9 years ago

I'm still getting to know famous, so when things are passed around always as "this" using syntax like:

_createMain = ->
   ...
   this.add(surf)

@StoryListView = ->
  View.apply this, arguments
  _createBack.call this

I find it a bit hard to follow what is what - lots of implicit objects are being passed around.

I know this is how famous has structured a lot of their code but it takes time to parse for me at least.

# declare we're expecting a rendertree (or view or node or whatever it is)
_createMain = (tree) ->
  ....
  tree.add(surf)

@StoryOneView = ->
  View.apply this, arguments   # this could also be clearer....
  _createMain(this)

this may potentially lose some flexibility in abstraction but it makes things clearer. in future if we ever did switch to using typescript or something to check parameters it could be helpful too.

dcsan commented 9 years ago

oh yeah also i really prefer coffeescript to plain JS... we can mix and match tho.

kakajansh commented 9 years ago

@dcsan yeah, for my personal projects I mostly used CoffeeScript, too. As all famo.us stuff was plain JS, I go with it. But in CoffeeScript I think it could look something like this:

class StoryOneView extends View
  @DEFAULT_OPTIONS:
    transition:
      duration: 300
      curve: Easing.outBack

  constructor: (@options)->
    super @options
    @_modifiers = []
    @_states = []

  _createMain: () ->
dcsan commented 9 years ago

that looks nice and clean!

i ended up doing this below so i can pass in the background to the scrollview for piping events around so you can click in the background to scroll too.

@StoryListView = ->
  View.apply this, arguments
  sc = _createScrollView.call this
  _createBack(this, sc)
  return