Skip to content

Commit

Permalink
fix: Add SSR support
Browse files Browse the repository at this point in the history
  • Loading branch information
evenchange4 committed May 31, 2019
1 parent 340a0de commit 3cb3663
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ let _throttle = require('lodash.throttle')

let supportsPassive = false
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true
},
})
window.addEventListener('testPassive', null, opts)
window.removeEventListener('testPassive', null, opts)
if (typeof window !== 'undefined') {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true
},
})
window.addEventListener('testPassive', null, opts)
window.removeEventListener('testPassive', null, opts)
}
} catch (e) {}

let getPosition = () => ({
x: window.pageXOffset,
y: window.pageYOffset,
})
let getPosition = () => {
if (typeof window === 'undefined') {
return { x: 0, y: 0 };
}
return {
x: window.pageXOffset,
y: window.pageYOffset,
};
};

let defaultOptions = {
throttle: 100,
Expand Down

0 comments on commit 3cb3663

Please sign in to comment.