Set up triggers and notifications

You can use the following code examples as a basis for configuring display components to implement triggers and notifications.

A component could receive and dismiss a notification as follows:

var NotificationServiceEvents = require('caplin/alerts/NotificationServiceEvents');
var notificationService = require('service!caplin.alerts.notification-service');
var newNotification;

notificationService.on(NotificationServiceEvents.ADDED, function(notification) {
  newNotification = notification;
});

notificationService.dismiss(newNotification);

A component could create a trigger and subsequently dispose it as follows:

var TriggerServiceEvents = require('caplin/alerts/TriggerServiceEvents');
var triggerService = require('service!caplin.alerts.trigger-service');
var newTrigger;

triggerService.on(TriggerServiceEvents.ADDED, function(trigger) {
  newTrigger = trigger;
});
triggerService.create(
  { subject: '/FX/GBPUSD', condition: 'BestBid > 1.7' },
  function() { alert('error creating trigger'); }
);

triggerService.on(TriggerServiceEvents.REMOVED, function(trigger) {
  alert('trigger with following subject removed: ' + trigger.getSubject());
});

triggerService.dispose(newTrigger, function() { alert ('error disposing trigger'); });

See also: