The weasl.onload Function

You might have noticed that the weasl JavaScript functions won't return a promise unless Weasl has been fully loaded on the page. You might need to do asynchronous work - things that depend on Weasl having loaded. Getting the current user, for example. If you need to block your computation to wait for Weasl to load, you can use the weasl.onload property.

weasl.onload = function(weaslApi) {
  // this.getCurrentUser() also works
  weaslApi.getCurrentUser().then(function(currentUser) {
    // not logged in
    if (currentUser === undefined) {
      window.loggedIn = false;
    } else {
      window.loggedIn = true;
      window.user = currentUser;

It has a very similar signature to the normal JavaScript onload function. The main difference is that the function is passed the API instead of the "onload" event that fired.

Did this help answer your question?

thumbs up
thumbs down

Thanks for the feedback! 🙏🏽

Help by drift