, , -, , , Angular.
Angular -
- /, /, Angular -
window document - Angular
importScripts - , ,
importScripts - .
, :
var window = self;
self.history = {};
var document = {
readyState: 'complete',
querySelector: function() {},
createElement: function() {
return {
pathname: '',
setAttribute: function() {}
}
}
};
importScripts('angular.js');
angular = window.angular;
importScripts('worker-app.js');
angular.bootstrap(null, ['worker-app']);
Angular : /, . , run ( console.log ).
(function() {
'use strict';
var app = angular.module('worker-app', []);
app.run(function($window) {
$window.onmessage = function(e) {
var workerResult = 'Result: ' + (e.data[0] * e.data[1]);
$window.postMessage(workerResult);
};
});
})();
, -:
describe('worker-app', function() {
'use strict';
var $window;
beforeEach(module('worker-app'));
beforeEach(inject(function(_$window_) {
$window = _$window_;
}));
beforeEach(function() {
spyOn($window, 'postMessage');
})
it('attaches to $window onmessage', function() {
var data = [2,3];
var result = 'Result: ' + (data[0] * data[1]);
$window.onmessage({data: data});
expect($window.postMessage).toHaveBeenCalledWith(result);
});
});
, Angular, , ! AngularJS v1.3.7.