Skip to content

Commit 300ac2e

Browse files
committed
old code moved to legacy folder, new es6 code started in js/app
1 parent 39604ea commit 300ac2e

File tree

9 files changed

+319
-1396
lines changed

9 files changed

+319
-1396
lines changed

assets/js/app/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import debounce from './utilities/debounce';
2+
3+
let app = {
4+
5+
start: function(){
6+
console.log('app started');
7+
8+
window.addEventListener('resize', debounce(() => {
9+
console.log('resize');
10+
}, 250));
11+
12+
}
13+
14+
15+
};
16+
17+
export default app;

assets/js/app/utilities/debounce.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Returns a function, that, as long as it continues to be invoked, will not
2+
// be triggered. The function will be called after it stops being called for
3+
// N milliseconds. If `immediate` is passed, trigger the function on the
4+
// leading edge, instead of the trailing.
5+
function debounce(func, wait, immediate) {
6+
let timeout;
7+
return function() {
8+
let context = this, args = arguments;
9+
let later = function() {
10+
timeout = null;
11+
if (!immediate) func.apply(context, args);
12+
};
13+
let callNow = immediate && !timeout;
14+
clearTimeout(timeout);
15+
timeout = setTimeout(later, wait);
16+
if (callNow) func.apply(context, args);
17+
};
18+
}
19+
20+
export default debounce;

0 commit comments

Comments
 (0)