Skylight Docs
Search
⌃K

Working with sessions

Creating, listing, updating, and closing Skylight sessions
SessionsRecipe.zip
5KB
Binary
Sessions Recipe Application Bundle

What does this recipe include?

The root view of the recipe consists of:
  • a card for creating a new session.
  • a card for closing all sessions.
  • a card that is has the list of all sessions (skylight.sessions) as its context, with an adapter that sorts the sessions by their current state (placing those that have properties.state === 'inprogress' before those that have properties.state === 'complete'. While the name and state of the session are displayed, note that we cannot display information in the session data because that requires having the session set as the current session. Selecting this card brings up two actions:
    • Setting the session as the current session and opening sessionView.
    • Updating the session, which will toggle the session's properties.state value between the strings inprogress and complete.
The session view of the recipe consists of:
  • a card that is bound to the name of the currently-set session.
  • a card that is bound to properties.state of the currently-set sessions.
  • a card that, when selected, will toggle the session's properties.state value between the strings inprogress and complete.
  • a card that, when selected, will increment session.data.count
  • a card that, when selected, will increment session.data.otherCount
  • a card that displays the current values for session.data.count and session.data.otherCount
  • a card that, when selected, will close the currently-set session.
There are two unused adapters in the list of application scripts that are included as examples for how sessions can be filtered based on property.
This recipe focuses on how skylight.session.update can be used to update the session's properties object. However, other parts of the sessions (such as its name and description) can be modified as well. That said, participants are added and removed using the skylight.session.addParticipant and skylight.session.removeParticipant methods.
Session data is patched using the skylight.session.saveData method rather than the skylight.session.update method, as seen in the count increment card scripts.
The skylight.session.update method overwrites the existing value for whatever session property is specified. This is particularly important to note when updating the session.properties property, as the entire object will be overwritten (unlike the way that skylight.session.saveData operates, which patches the object). The best practice is to retrieve the existing properties object, create a copy of it (as it is immutable), modify the copy, then call skylight.session.update with the modified copy of the session's properties.
There are several instances in this recipe where we write defensive code to make sure we can work with sessions that may not have a properties object. While every session in this recipe is created with properties specified, it is recommended to assume that there may exist sessions where properties is undefined.