Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Lifecycle

bruth edited this page Dec 30, 2014 · 2 revisions

Cilantro is a single page application (SPA) which means that it is responsible for handling the browser history (back button) and rendering the appropriate data and views on the page for each URL.

Cilantro comes with a cilantro/main module that does all the setup of the session, data, and routes, but when customization is required, application code can override or inject functionality into Cilantro. Below is an ordered listing of events that make the lifecycle of Cilantro.

Cilantro

Events are triggered by the cilantro object.

init

The application has initialized and has begun loading external dependencies defined in the configuration. Additional dependencies and configuration tweaking can be done here. See #754

c.on('init', function(c) {
    // Do additional setup
});

ready

The application has loaded all external dependencies and is ready to open a session. Views that do not require any data can be initialized and rendered.

c.on('ready', function(c) {
    c.sessions.open({ ... });
});

Session

Events are triggered on the cilantro.sessions object. See #755

session:opening

The request to the service root has been sent and waiting for a response.

c.sessions.on('session:opening', function(session) {
    // Display notification..
});

session:unauthorized

The client is not authorized to connect to the service. For services that require authentication, credentials can be supplied when opening the session.

c.sessions.open({
    credentials: {
        username: 'foo',
        password: 'secr3t'
    }
});

session:error

An unknown error occurred while opening the session. This is usually due to a service error.

c.sessions.on('session:error', function(session, error) {
    // Display notification..
});

session:opened

The session has been successfully opened, the data stores have been initialized, and referenced at session.data. Views that require data can be initialized. For convenience, a reference to the active session is available at cilantro.session.

c.sessions.on('session:opened', function(session) {
    // Start rendering data-driven views..
});

session:closed

The session has been closed. All data for the session has been dereferenced.

URL Routing

Once the session is opened and views have been initialized, the next step is to define the URL routes. This is a mapping between the URL and a set of views that should be rendered on the page when that URL is navigated to. The cilantro/main module comes with a set of routes for the workspace, query, and results pages.

Once the routes have been declared, they are passed in the session.start() method to trigger the route for the current URL.

Data

Note: These data events are deprecated.

  • CONCEPT_FOCUS(id) - The concept identified by id has gained focus.
  • CONTEXT_SYNCED(context, status) - A context has synced. status may be success or error.
  • CONTEXT_INVALID(invalidFilters) - A context is not valid due to one or more filters.
  • VIEW_SYNCING(view) - A view is syncing.
  • VIEW_SYNCED(view, status) - A view has synced. status may be success or error.
  • VIEW_CHANGED(view) - A view changed.