From 16d160394f456bc70e93331663294d4397912223 Mon Sep 17 00:00:00 2001 From: streamich Date: Tue, 25 Dec 2018 11:58:38 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20improve=20viewport=20sens?= =?UTF-8?q?ors=20and=20speed=20up=20Storybook?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .storybook/webpack.config.js | 10 +++++++++- src/ViewportObserverSensor/__story__/story.tsx | 12 ++++++------ src/ViewportScrollSensor/__story__/story.tsx | 12 ++++++------ src/ViewportScrollSensor/index.ts | 6 +++--- src/ViewportSensor/index.ts | 11 ++++++----- 5 files changed, 30 insertions(+), 21 deletions(-) diff --git a/.storybook/webpack.config.js b/.storybook/webpack.config.js index 3dd9a77b..9043b15b 100644 --- a/.storybook/webpack.config.js +++ b/.storybook/webpack.config.js @@ -1,4 +1,5 @@ const path = require('path'); +const {compilerOptions} = require('../tsconfig.json'); const SRC_PATH = path.join(__dirname, '../src'); @@ -10,7 +11,14 @@ module.exports = { loader: 'ts-loader', include: [ SRC_PATH, - ] + ], + options: { + transpileOnly: true, // use transpileOnly mode to speed-up compilation + compilerOptions: { + ...compilerOptions, + declaration: false, + }, + }, } ] }, diff --git a/src/ViewportObserverSensor/__story__/story.tsx b/src/ViewportObserverSensor/__story__/story.tsx index 089fddfd..2cf8d4b4 100644 --- a/src/ViewportObserverSensor/__story__/story.tsx +++ b/src/ViewportObserverSensor/__story__/story.tsx @@ -8,16 +8,16 @@ import StoryViewportSensorConf from './StoryViewportSensorConf'; storiesOf('Sensors/ViewportSensor/ViewportObserverSensor', module) .add('Basic example', () => - ) + ) .add('Horizontal', () => - ) + ) .add('Threshold 0%', () => - ) + ) .add('Threshold 25%', () => - ) + ) .add('Threshold 75%', () => - ) + ) .add('Threshold 100%', () => - ) + ) .add('Threshold 100%, margin 100px', () => ); diff --git a/src/ViewportScrollSensor/__story__/story.tsx b/src/ViewportScrollSensor/__story__/story.tsx index 73a75fa7..6be9f13e 100644 --- a/src/ViewportScrollSensor/__story__/story.tsx +++ b/src/ViewportScrollSensor/__story__/story.tsx @@ -8,16 +8,16 @@ import StoryViewportSensorConf from '../../ViewportObserverSensor/__story__/Stor storiesOf('Sensors/ViewportSensor/ViewportScrollSensor', module) .add('Basic example', () => - ) + ) .add('Horizontal', () => - ) + ) .add('Threshold 0%', () => - ) + ) .add('Threshold 25%', () => - ) + ) .add('Threshold 75%', () => - ) + ) .add('Threshold 100%', () => - ) + ) .add('Threshold 100%, margin 100px', () => ); diff --git a/src/ViewportScrollSensor/index.ts b/src/ViewportScrollSensor/index.ts index a3f6f878..0e4a4507 100644 --- a/src/ViewportScrollSensor/index.ts +++ b/src/ViewportScrollSensor/index.ts @@ -56,7 +56,7 @@ export interface IViewportScrollSensorState { visible: boolean; } -export class ViewportScrollSensor extends Component { +export class ViewportScrollSensor extends Component { static defaultProps = { threshold: 0, throttle: 50, @@ -66,9 +66,9 @@ export class ViewportScrollSensor (el) => { this.el = el; diff --git a/src/ViewportSensor/index.ts b/src/ViewportSensor/index.ts index 84e2e518..4889c119 100644 --- a/src/ViewportSensor/index.ts +++ b/src/ViewportSensor/index.ts @@ -5,11 +5,12 @@ import faccToHoc, {divWrapper} from '../util/faccToHoc'; let Sensor: any = ViewportObserverSensor; -if (!(window as any).IntersectionObserver) { - const loader = () => import('../ViewportScrollSensor').then((module) => module.ViewportScrollSensor); - - Sensor = loadable({loader}); - Sensor.load(); +if (typeof window === 'object') { + if (!(window as any).IntersectionObserver) { + const loader = () => import('../ViewportScrollSensor').then((module) => module.ViewportScrollSensor); + Sensor = loadable({loader}); + Sensor.load(); + } } export const ViewportSensor: React.StatelessComponent = (props) => {