Skip to content

Commit 10eee4e

Browse files
committed
Merge pull request #96 from guilhermef/master
Included a RavenCallback global that allows loaded callbacks
2 parents 5a3a21a + 0b0d9e9 commit 10eee4e

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

plugins/console.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@ var originalConsole = console,
55
logLevels = ['debug', 'info', 'warn', 'error'],
66
level;
77

8-
while(level = logLevels.pop()) {
9-
console[level] = function () {
8+
var logForGivenLevel = function(level) {
9+
return function () {
1010
var args = [].slice.call(arguments);
1111
Raven.captureMessage('' + args, {level: level, logger: 'console'});
1212

1313
// this fails for some browsers. :(
14-
originalConsole[level] && originalConsole[level].apply(null, args);
14+
if (originalConsole[level]) {
15+
originalConsole[level].apply(null, args);
16+
}
1517
};
18+
};
19+
20+
21+
level = logLevels.pop();
22+
while(level) {
23+
console[level] = logForGivenLevel(level);
24+
level = logLevels.pop();
1625
}
1726
// export
1827
window.console = console;

src/raven.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ TK.remoteFetching = false;
3030
var Raven = {
3131
VERSION: '@VERSION',
3232

33+
/*
34+
* Allow Raven to be configured as soon as it is loaded
35+
* It uses a global RavenConfig = {dsn: '...', config: {}}
36+
*
37+
* @return undefined
38+
*/
39+
afterLoad: function() {
40+
var globalConfig = window.RavenConfig;
41+
if (globalConfig) {
42+
this.config(globalConfig.dsn, globalConfig.config).install();
43+
}
44+
},
45+
3346
/*
3447
* Allow multiple versions of Raven to be installed.
3548
* Strip Raven from the global context and returns the instance.
@@ -496,3 +509,5 @@ function joinRegExp(patterns) {
496509
while (i--) sources[i] = patterns[i].source;
497510
return new RegExp(sources.join('|'), 'i');
498511
}
512+
513+
Raven.afterLoad();

test/raven.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,29 @@ describe('Raven (public API)', function() {
731731
});
732732
});
733733

734+
describe('callback function', function() {
735+
it('should callback a function if it is global', function() {
736+
window.RavenConfig = {
737+
dsn: "http://[email protected]:80/2",
738+
config: {some: 'config'}
739+
};
740+
741+
this.sinon.stub(window, 'isSetup').returns(false);
742+
this.sinon.stub(TK.report, 'subscribe');
743+
744+
Raven.afterLoad();
745+
746+
assert.equal(globalKey, 'random');
747+
assert.equal(globalServer, 'http://some.other.server:80/api/2/store/');
748+
assert.deepEqual(globalOptions.ignoreErrors, ['Script error.'], 'it should install "Script error." by default');
749+
assert.equal(globalOptions.some, 'config');
750+
assert.equal(globalProject, 2);
751+
752+
assert.isTrue(window.isSetup.calledOnce);
753+
assert.isFalse(TK.report.subscribe.calledOnce);
754+
});
755+
});
756+
734757
describe('.config', function() {
735758
it('should work with a DSN', function() {
736759
assert.equal(Raven, Raven.config(SENTRY_DSN, {foo: 'bar'}), 'it should return Raven');

0 commit comments

Comments
 (0)