The module:caplin/watchlist/WatchlistService
handles creation, disposal and retrieval of watchlists.
The module:caplin/watchlist/Watchlist
represents a watchlist, provides access to metadata and
generates a module:caplin/watchlist/WatchlistContentsManager
,
which provides access to the watchlist contents.
Stubs that implement these interfaces are provided along a service fixture enabling Verifier acceptance tests to be written for components that use these services.
Watchlist API
The WatchlistService interface is an emitter that notifies any listeners of the following events defined in
caplin/watchlist/WatchlistServiceEvents
:
-
ADDED
- when a new watchlist is added. -
REMOVED
- when a watchlist has been removed. -
STATUS_CHANGED
- when the watchlist service's availability changes, assuming one of the values inmodule:caplin/services/ServiceStatus
.
The WatchlistService provides create
and dispose
methods so that components can create
and dispose watchlists. Note that create takes a name string to create a single watchlist, and dispose takes
an array of Watchlist objects, so it can dispose multiple watchlists at once.
A component could create a watchlist and subsequently dispose it as follows:
var WatchlistServiceEvents = require('caplin/watchlist/WatchlistServiceEvents'); var newWatchlist; var watchlistService = ServiceRegistry.getService('caplin.watchlist.watchlist-service'); watchlistService.on(WatchlistServiceEvents.ADDED, function(watchlist) { newWatchlist = watchlist; alert('watchlist with following name has been added: ', watchlist.getName()); }); var errorCallback = function() { alert('error creating watchlist'); } watchlistService.create( 'FX Majors', errorCallback ); watchlistService.on(WatchlistServiceEvents.REMOVED, function(watchlist) { alert('watchlist with following subject removed: ' + watchlist.getSubject()); }); watchlistService.dispose([ newWatchlist ], function() { alert('error disposing watchlist'); });
A component could disable itself when the WatchlistService becomes unavailable as follows:
var ServiceStatus = require('caplin/services/ServiceStatus'); var WatchlistServiceEvents = require('caplin/watchlist/WatchlistServiceEvents'); watchlistService.on(WatchlistServiceEvents.STATUS_CHANGED, function(status) { if(status !== ServiceStatus.AVAILABLE) { disableComponent(); } });