Revert debounce.
This commit is contained in:
parent
3a3c640ef2
commit
13ede8cfb7
|
@ -1,6 +1,5 @@
|
|||
/* eslint-disable no-param-reassign, prefer-template, no-void, consistent-return */
|
||||
|
||||
import _ from 'underscore';
|
||||
import AccessorUtilities from './lib/utils/accessor';
|
||||
|
||||
export default class Autosave {
|
||||
|
@ -14,13 +13,7 @@ export default class Autosave {
|
|||
this.key = 'autosave/' + key;
|
||||
this.field.data('autosave', this);
|
||||
this.restore();
|
||||
this.field.on('keyup', this.debounceInputHandler());
|
||||
}
|
||||
|
||||
debounceInputHandler() {
|
||||
return _.debounce(() => {
|
||||
this.save();
|
||||
}, Autosave.DEBOUNCE_TIMER);
|
||||
this.field.on('input', () => this.save());
|
||||
}
|
||||
|
||||
restore() {
|
||||
|
@ -64,6 +57,4 @@ export default class Autosave {
|
|||
dispose() {
|
||||
this.field.off('input');
|
||||
}
|
||||
|
||||
static DEBOUNCE_TIMER = 300;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import $ from 'jquery';
|
||||
import _ from 'underscore';
|
||||
import Autosave from '~/autosave';
|
||||
import AccessorUtilities from '~/lib/utils/accessor';
|
||||
|
||||
|
@ -11,24 +10,12 @@ describe('Autosave', () => {
|
|||
describe('class constructor', () => {
|
||||
beforeEach(() => {
|
||||
spyOn(AccessorUtilities, 'isLocalStorageAccessSafe').and.returnValue(true);
|
||||
spyOn(_, 'debounce');
|
||||
spyOn(Autosave.prototype, 'save');
|
||||
spyOn(Autosave.prototype, 'restore');
|
||||
autosave = new Autosave(field, key);
|
||||
});
|
||||
|
||||
it('should debounce the input handler', () => {
|
||||
expect(_.debounce).toHaveBeenCalled();
|
||||
expect(autosave.save).not.toHaveBeenCalled();
|
||||
|
||||
const [cb, timer] = _.debounce.calls.argsFor(0);
|
||||
cb(); // execute debounced callback
|
||||
|
||||
expect(timer).toEqual(Autosave.DEBOUNCE_TIMER);
|
||||
expect(autosave.save).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should set .isLocalStorageAvailable', () => {
|
||||
autosave = new Autosave(field, key);
|
||||
|
||||
expect(AccessorUtilities.isLocalStorageAccessSafe).toHaveBeenCalled();
|
||||
expect(autosave.isLocalStorageAvailable).toBe(true);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue