Skip to content

Commit

Permalink
fix issue where FilePond internal event mechanism would be in slowmot…
Browse files Browse the repository at this point in the history
…ion mode when running in an inactive tab because of `setTimeout` use.
  • Loading branch information
rikschennink committed Apr 14, 2020
1 parent 101883f commit 7f09f39
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 4.13.4

- Fix issue where FilePond internal event mechanism would be in slowmotion mode when running in an inactive tab because of `setTimeout` use.


## 4.13.3

- Fix issue where FilePond would excessivly pause in between processing files while running in an inactive tab.
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.13.3
* FilePond 4.13.4
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down
16 changes: 10 additions & 6 deletions dist/filepond.esm.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.13.3
* FilePond 4.13.4
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -1659,6 +1659,14 @@ const getUniqueId = () =>

const arrayRemove = (arr, index) => arr.splice(index, 1);

const fire = cb => {
if (document.hidden) {
Promise.resolve(1).then(cb);
} else {
setTimeout(cb, 0);
}
};

const on = () => {
const listeners = [];
const off = (event, cb) => {
Expand All @@ -1674,11 +1682,7 @@ const on = () => {
listeners
.filter(listener => listener.event === event)
.map(listener => listener.cb)
.forEach(cb => {
setTimeout(() => {
cb(...args);
}, 0);
});
.forEach(cb => fire(() => cb(...args)));
},
on: (event, cb) => {
listeners.push({ event, cb });
Expand Down
4 changes: 2 additions & 2 deletions dist/filepond.esm.min.js

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions dist/filepond.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* FilePond 4.13.3
* FilePond 4.13.4
* Licensed under MIT, https://opensource.org/licenses/MIT/
* Please visit https://pqina.nl/filepond/ for details.
*/
Expand Down Expand Up @@ -1951,6 +1951,14 @@
return arr.splice(index, 1);
};

var _fire = function fire(cb) {
if (document.hidden) {
Promise.resolve(1).then(cb);
} else {
setTimeout(cb, 0);
}
};

var on = function on() {
var listeners = [];
var off = function off(event, cb) {
Expand Down Expand Up @@ -1980,9 +1988,9 @@
return listener.cb;
})
.forEach(function(cb) {
setTimeout(function() {
cb.apply(void 0, args);
}, 0);
return _fire(function() {
return cb.apply(void 0, args);
});
});
},
on: function on(event, cb) {
Expand Down
2 changes: 1 addition & 1 deletion dist/filepond.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/filepond.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "filepond",
"version": "4.13.3",
"version": "4.13.4",
"description": "FilePond, Where files go to stretch their bits.",
"license": "MIT",
"author": {
Expand Down
15 changes: 10 additions & 5 deletions src/js/app/utils/on.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { arrayRemove } from '../../utils/arrayRemove';

const fire = (cb) => {
if (document.hidden) {
Promise.resolve(1).then(cb);
}
else {
setTimeout(cb, 0);
}
}

export const on = () => {
const listeners = [];
const off = (event, cb) => {
Expand All @@ -15,11 +24,7 @@ export const on = () => {
listeners
.filter(listener => listener.event === event)
.map(listener => listener.cb)
.forEach(cb => {
setTimeout(() => {
cb(...args);
}, 0);
});
.forEach(cb => fire(() => cb(...args)));
},
on: (event, cb) => {
listeners.push({ event, cb });
Expand Down

0 comments on commit 7f09f39

Please sign in to comment.