Promises and lifecycle

The weavy lifecycle is highly asynchronous and has a bunch useful promises and events to act upon at different parts of the cycle.

The promise will let you wait for things to happen or if it already has happened execute instantly. It also executes asynchronously, which allows the code execution to continue.

The promise is always exposed on the object that it relates to. Some methods may also return a related promise, so that you may wait for the method to be resolved.

Asynchronous lifecycle

All these promises are part of the asyncrounous lifecycle in weavy. They have no explicit given order, although some events in the lifecycle might be dependent on others.

Weavy promises

Promise Description
whenInitialized() When initialization has been started.
whenReady() When frames, storage access, cors and other requirements has been checked.
whenBuilt() When all initial DOM nodes has been built.
whenConnected() When realtime websocket has been connected.
whenLoaded() After loading of all data and all current apps is complete.

Authentication promises

Promise Description
authentication.whenAuthenticated() When user authentication has been established, regardless if the user is signed in or anonymous.
authentication.whenAuthorized() When a signed in user has been established.

App promises

Promise Description
app.whenInitialized() When the app has been fetched from the backend.
app.whenBuilt() When the DOM nodes for the app has been built.
app.whenLoaded() When the app has loaded in the frame.

Usage

All promises are exposed via functions. You can use Promise.all() to wait for multiple promises at once.

Traditional promise syntax

weavy.whenLoaded().then(function () {
  /* Executed when weavy and all current apps has loaded */
});

weavy.authentication.whenAutorized().then(function () {
  /* Executed when a user is signed in */
});

ES2017 async/await promise syntax

async function doSomething() {
  await weavy.whenLoaded();
  /* Executed when weavy and all current apps has loaded */
}
Weavy Docs