Skip to content

Commit

Permalink
Do not debounce callback anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck committed Feb 18, 2016
1 parent ebe0208 commit 38dcccb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
39 changes: 5 additions & 34 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,21 @@
'use strict';

// Grabbed from underscore.js
// http://underscorejs.org/#debounce
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) {
func.apply(context, args);
}
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) {
func.apply(context, args);
}
};
}

var gitHubInjection = function (global, options, cb) {
var gitHubInjection = function (global, cb) {
if (!global) {
throw new Error('Missing argument global');
}

if (!global.document || !global.document.getElementById) {
throw new Error('The given argument global is not a valid window object');
}

if (!cb) {
cb = options;
options = {};
} else if (typeof cb !== 'function') {
throw new Error('Callback is not a function');
}

if (!cb) {
throw new Error('Missing argument callback');
}

options = options || {};
options.context = options.context || null;
options.wait = options.wait || 250;

cb = debounce(cb, options.wait).bind(options.context);
if (typeof cb !== 'function') {
throw new Error('Callback is not a function');
}

var domElement = global.document.getElementById('js-repo-pjax-container');
if (!domElement || !global.MutationObserver) {
Expand Down
4 changes: 0 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ describe('GitHub-Injection', function() {
it('accept a callback argument', function (done) {
assert.doesNotThrow(injection.bind(null, fakeWindow, done));
});

it('accept a options and callback argument', function (done) {
assert.doesNotThrow(injection.bind(null, fakeWindow, {}, done));
});
});

describe('markup', function() {
Expand Down

0 comments on commit 38dcccb

Please sign in to comment.