Using Mithril
We use Mithril to provide our browser based
Model View Controller. Mithril provides tools to work asynchronously with
the server using promises,
typically provided by the Mithril request
interface. Mithril objects, called
components, are simply Plain
Old JavaScript
Objects
which have a view
method.
Any Mithril component is itself a model which can hold its own state.
Any Mithril component integrates with the browser's underlying view by
implementing a view
method.
Any Mithril component integrates with the browser's underlying controller by adding any of the standard GlobalEventHandlers as an attribute.
Our use of Mithril
Any Mithril component which is related in some way to information on the server, will consist of a mixin of the following two interfaces:
-
A Mithril View mixin, which uses a Mithril
view
method to display the component to the user. -
A Mithril Connector mixin, which uses a Mithril request to obtain the component data for a particular target URL on the server, via a HTTP request to the MajorDomo server's REST interface.
These two mixin parts of a Mithril component will "communicate" using a
common data
property. The pairing itself will be determined by the
unique prefix of each URL. This means that different server URL mount
points must have unique prefixes.
We will implement this mixin pattern using the Object.assign() method.