WARNING: This is a wiki used as a scratch-book. The texts on this wiki are being worked on actively, and are considered to be drafts.
= What is the Roundcube Shell? =
The Roundcube Shell builds the basic environment for the Roundcube Next client. It's based on Ember.js and provides the following core functionality:
As an application:
- Authentication UI
- Top-level navigation between full-page apps
- User settings page (for simple account tweaks, password changes, etc)
As an API:
- Access to the data store via the JMAP library
- UI Toolkit with reusable components
- Routing system with hooks
- Pub/sub system for inter-component communication
== JMAP data store ==
TBD.
== UI Toolkit ==
When working with Ember, most widgets are contained within [[ http://guides.emberjs.com/v1.10.0/components/ | Components ]]. Components which are expected to be repeatedly used within the various applications that Roundcube Next shall come with, ought to be provided as a reusable set by Roundcube Shell. This would range from simple things like buttons and labels to more complex components like list-views and editor toolbars.
Having all components in one place lets us keep them organized and allows for an easy way to customize the look of the entire application consistently, making it very smooth for designers and developers to work together. Every time a new reusable component is created, it should be added to a living //styleguide//. For realizing this, we shall use [[ https://github.com/livingstyleguide/broccoli-livingstyleguide | broccoli-livingstyleguide ]], which is designed for ember-cli backed toolchains.
== Routing system ==
TBD.
== Pub/sub system ==
The shell also provides a global event emitter system where all components and apps can use to publish notifications and subscribe to messages from other components. Each component shall emit events
- whenever it reaches a point where the application state is changed
- where it makes sense to inform others about a certain action
- where feedback and/or additional/modified data is desired
This can begin with an `shell.init` event at application startup where apps can register themselves in the shell, define routes and push items to the main navigation.
The pup/sub is inspired by the [[ https://nodejs.org/api/events.html | Node.js events.EventEmitter ]] component and primarily provides three methods for public use: `on()`, `once()` and `emit()`. Bonus points if the registration of event listeners with `on()` supports wildcard event names such as `mail.message.*`.
NOTE: Shall the App instance itself provide the pub/sub methods or shall we define a specific (singleton) module that can be imported? Any suggestions for existing libraries to use for this?
=== Works with Promises ===
Event listener should be able to work asynchronously and therefore return a Promise. The pub/sub system collects Promises returned by the registered listeners and returns a list of Promises to the emitter. Thus, whoever emits an event through the pub/sub system is responsible to handle returned promises and execute them. Example:
lang=js
Promise.all(pubsub.emit('foo.bar')).then(function(results) { /* continue */ }).catch(...);
=== Naming conventions ===
Since the proposed pub/sub system is one global message bus, it's important to use unique names for the events emitted to it. A few rules apply for composing event names:
# each component (or app) emitting an event, shall prefix the name with its own namespace (e.g. `shell.*`).
# the general classification of the emitting component and the entity name shall be reflected in the event name (e.g. `model.message` or `view.contactlist`).
# finally, choose sane names describing the action performed before the event is emitted.
# by default, events are emitted **after** a certain action was performed.
# if events are emitted //before// and //after// the according action, this shall be reflected in the event name with the `before` and `after` keywords.
Here are a few examples, illustrating the just listed conventions:
- `shell.init`
- `shell.ui.load`
- `mail.model.mailboxlist.load`
- `mail.model.message.flags.set`
- `mail.view.mailboxlist.render`
- `shell.account.settings.beforesave`
- `shell.account.settings.aftersave`
=== Documentation ===
In order to publish a comprehensive list of events emitted throughout the application, each component shall describe the emitted events and the provided parameters in a jsdoc block according to the [[https://github.com/senchalabs/jsduck/wiki/@event | JSDuck spec]]:
/**
* @event mail.model.message.flags.set
* Emitted when message flags are updated
* @param {Mail.Model.Message} message The message object receiving flag updates
* @param {Object} flags Map of flag names and their new values
*/
= User Stories =
TBD.