Skip to content

Commit

Permalink
closes #2
Browse files Browse the repository at this point in the history
improves drag performance by only dragging every 20ms
  • Loading branch information
michaelmalonenz committed Mar 15, 2016
1 parent c2dca09 commit 220b336
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/dragula.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {Util} from './util';
import {Emitter} from './emitter';
import * as classes from './classes';

const MIN_TIME_BETWEEN_REDRAWS_MS = 20;

@inject(GLOBAL_OPTIONS)
export class Dragula {
Expand Down Expand Up @@ -194,6 +195,8 @@ export class Dragula {
this._initialSibling = context.item.nextSibling;
this._currentSibling = Util.nextEl(context.item);

this._timeSinceLastMove = Date.now() + MIN_TIME_BETWEEN_REDRAWS_MS; //ensure that the first frame draws...

this.dragging = true;
this.emitter.emit('drag', this._item, this._source);
}
Expand Down Expand Up @@ -337,6 +340,11 @@ export class Dragula {
if (!this._mirror) {
return;
}

if (Date.now() - this._timeSinceLastMove <= MIN_TIME_BETWEEN_REDRAWS_MS) {
return;
}
this._timeSinceLastMove = Date.now();
e.preventDefault();

let moved = (type) => { this.emitter.emit(type, item, this._lastDropTarget, this._source); }
Expand Down

0 comments on commit 220b336

Please sign in to comment.