Skip to content

Commit 4b47c5c

Browse files
committed
rename ParallaxScrollListener to ParallaxScroller; convert to singleton pattern and export from index
1 parent 6b1a333 commit 4b47c5c

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export Parallax from './components/Parallax';
2+
export ParallaxScroller from './libs/ParallaxScroller';

src/libs/ParallaxScrollListener.js renamed to src/libs/ParallaxScroller.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
testForPassiveScroll,
55
} from '../utils/index';
66

7-
(function(window, document) {
7+
const ParallaxScroller = (function() {
88

99
function ParallaxScrollListener() {
1010

@@ -349,10 +349,19 @@ import {
349349

350350
// Initialize the Parallax scroll listener
351351
_addListeners();
352-
353352
}
354353

355-
window.ParallaxScrollListener = new ParallaxScrollListener();
354+
return {
355+
// Return the singleton instance if one exists
356+
// or create one if it doesn't
357+
init: function() {
358+
if (!window.ParallaxScrollListener) {
359+
window.ParallaxScrollListener = new ParallaxScrollListener();
360+
}
361+
return window.ParallaxScrollListener;
362+
},
363+
};
364+
})();
356365

357-
})(window, document);
366+
export default ParallaxScroller;
358367

0 commit comments

Comments
 (0)