-
Notifications
You must be signed in to change notification settings - Fork 11
/
annyang-service.js
38 lines (28 loc) · 1.01 KB
/
annyang-service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(function(annyang) {
'use strict';
function AnnyangService($rootScope) {
var service = {};
// COMMANDS
service.commands = {};
service.addCommand = function(phrase, callback) {
var command = {};
// Wrap annyang command in scope apply
command[phrase] = function(args) {
$rootScope.$apply(callback(args));
};
// Extend our commands list
angular.extend(service.commands, command);
// Add the commands to annyang
annyang.addCommands(service.commands);
console.debug('added command "' + phrase + '"', service.commands);
};
service.start = function() {
annyang.addCommands(service.commands);
annyang.debug(true);
annyang.start();
};
return service;
}
angular.module('myApp')
.factory('AnnyangService', AnnyangService);
}(window.annyang));