done callback to support async setup #50

Open
wilsonpage opened this Issue Oct 22, 2013 · 4 comments

Projects

None yet

2 participants

@wilsonpage

I can foresee a point when we will require a callback from setup to tell us when all the modules in the view tree have finished setting up.

Inside module definition:

setup: function(done) {
  fastdom.write(function() {
    // do stuff
   done();
  });
},

Then when we setup our view in our app:

view
  .render()  
  .setup(function() {
    // All the modules have finished
    // let's show the user the view.
  });
@matthew-andrews
FT Labs member

Does this go far enough? Do we want render to be async too?

If so should we return promises from our fm methods instead:

view
  .render()
  .then(function() {
    return view.setup()
  })
  .then(function() {
    // All the modules have finished
    // let's show the user the view.
  });
@matthew-andrews
FT Labs member

Feels less clean though :-(

@wilsonpage

I don't see a use case for render being async. Perhaps teardown/destroy? I also don't like the cruft that promises bring. If we provide callbacks, people can wrap fruitmachine API to add promises if they like that sugar.

If people don't like promises, they still have to carry their weight, and added library complexity. Promises bring just opinionated sugar, no added functionality (IMHO).

@matthew-andrews
FT Labs member

You should totally drink the Kool-Aid :P. Seriously though IMHO promises are a very powerful and flexible approach.

That said implementing them would break a lot of APIs and could work along side your suggested approach for callbacks in the future so I suggest we shelve the promises suggestion for now and implement as you originally suggested :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment