Sauron
Mediator pattern for Halo, a client-side MVC framework.
Synopsis
Sauron was designed as a core component of Halo; providing a loose channel system for talking between models and controllers.
Getting Started
Download the production version (vanilla or requirejs) or the development version (vanilla or requirejs).
In your web page:
Documentation
Sauron can talk in the controller
, model
, or no namespace.
Within all namespaces, we can modify events to be subscriptions, on
, unsubscriptions, off
, or emissions/triggers, voice
. By default, if a namespace has a terminating method called (e.g. start
for controller
) and there is no modifier, voice
will be called.
Terminating methods for the controller
namespace are start
and stop
.
Sauronstart;
Terminating methods for the model
namespace are create
, retrieve
, update
, delete
, createEvent
, updateEvent
, and deleteEvent
.
Sauron;
Examples
Listening for an event
Sauronstart { console;};
Triggering an event
Sauron;
Unsubscribing from an event internally
Sauron;
Unsubscribing from an event externally
var { console;};Sauron;Sauron;
API
Sauron;/** * Retrieval function for the current channel * @param * @returns */ Sauron;/** * Adds a new subchannel to the current channel * @param * @returns */ Sauron;/** * Subscribing function for event listeners * @param * @param * @returns */ Sauron;/** * Unsubscribing function for event listeners * @param * @param * @returns */ Sauron;/** * Voice/emit command for Sauron * @param * @param * @returns */ Sauron;/** * Returns a cloned copy of this * @returns */ Sauron;/** * Sugar subscribe function that listens to an event exactly once * @param * @param * @returns */ Sauron;/** * Helper function for error first callbacks. If an error occurs, we will log it and not call the function. * @param * @returns */ // CONTROLLER METHODS Sauron;/** * Fluent method for calling out a controller * @param * @param * @returns */ Sauron;/** * Method for creating controllers * @param * This will ALWAYS call the (on, off, once, voice) function. */ Sauronstartparam1 param2 ...;Sauron;/** * Methods for starting/stopping controllers. Will call previous action if there was any (e.g. on, off, once). */ // MODEL METHODS Sauron;// Same as Sauron.controller except for models Sauron;// Same as Sauron.createController except for models Sauroncreate|retrieve|update|deleteEvent?param1 param2 ...;// Same as Sauron.start except for models// Names expand to create, createEvent, retrieve, ..., deleteEvent
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint your code using grunt and test via the instructions below.
Also, please don't edit files in the "dist" or "stage" subdirectories as they are generated via grunt. You'll find source code in the "lib" subdirectory!
Testing
The test suite is written in Mocha (with a crossbones wrapper) for in-browser testing. Start up the server, navigate to the test page, and the test will begin.
# If you do not have serve installed install itsudo npm install -g serve # Begin hosting a serverserve # Navigate to the test pagebrowser http://localhost:3000/src-test/Sauron.test.html
License
Copyright (c) 2013 Ensighten Licensed under the MIT license.