Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

done callback to support async setup #50

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

done callback to support async setup #50

wilsonpage opened this issue Oct 22, 2013 · 4 comments

Comments

@wilsonpage
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

Feels less clean though :-(

@wilsonpage
Copy link
Contributor Author

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
Copy link
Contributor

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants