From 05b7c969cbc6dae6b8dc862d9a25c3744f9fdf5c Mon Sep 17 00:00:00 2001 From: Kir Belevich Date: Sat, 19 Aug 2017 13:42:01 +0200 Subject: [PATCH] :boom: :wrench: safe-timers: refactor using "eager factory" --- packages/safe-timers/package.json | 2 +- .../{safeTimerFactory.jsx => safeTimerFactory.js} | 14 ++++++-------- .../__snapshots__/withSafeAnimationFrame.jsx.snap | 8 +------- .../__snapshots__/withSafeIdleCallback.jsx.snap | 8 +------- .../test/__snapshots__/withSafeInterval.jsx.snap | 8 +------- .../test/__snapshots__/withSafeTimeout.jsx.snap | 8 +------- 6 files changed, 11 insertions(+), 37 deletions(-) rename packages/safe-timers/src/{safeTimerFactory.jsx => safeTimerFactory.js} (81%) diff --git a/packages/safe-timers/package.json b/packages/safe-timers/package.json index 835ec0c..fb2d3fe 100644 --- a/packages/safe-timers/package.json +++ b/packages/safe-timers/package.json @@ -30,6 +30,6 @@ }, "peerDependencies": { "react": "^15.6.1", - "recompose": "^0.24.0" + "recompose": "^0.25.0" } } diff --git a/packages/safe-timers/src/safeTimerFactory.jsx b/packages/safe-timers/src/safeTimerFactory.js similarity index 81% rename from packages/safe-timers/src/safeTimerFactory.jsx rename to packages/safe-timers/src/safeTimerFactory.js index 772cf0b..3f64ce9 100644 --- a/packages/safe-timers/src/safeTimerFactory.jsx +++ b/packages/safe-timers/src/safeTimerFactory.js @@ -1,7 +1,9 @@ -import React, { Component } from 'react'; -import { setDisplayName, wrapDisplayName } from 'recompose'; +import { Component } from 'react'; +import { createEagerFactory, setDisplayName, wrapDisplayName } from 'recompose'; const safeTimerFactory = (setFn, clearFn, propName, hocName) => (Target) => { + const factory = createEagerFactory(Target); + class SafeTimer extends Component { constructor(props, context) { super(props, context); @@ -26,14 +28,10 @@ const safeTimerFactory = (setFn, clearFn, propName, hocName) => (Target) => { } render() { - const props = { + return factory({ ...this.props, [propName]: this[propName] - }; - - return ( - - ); + }); } } diff --git a/packages/safe-timers/test/__snapshots__/withSafeAnimationFrame.jsx.snap b/packages/safe-timers/test/__snapshots__/withSafeAnimationFrame.jsx.snap index bc4cd35..ba49995 100644 --- a/packages/safe-timers/test/__snapshots__/withSafeAnimationFrame.jsx.snap +++ b/packages/safe-timers/test/__snapshots__/withSafeAnimationFrame.jsx.snap @@ -1,12 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`withSafeAnimationFrame display name should not wrap display name in production env 1`] = ` - - - -`; +exports[`withSafeAnimationFrame display name should not wrap display name in production env 1`] = ``; exports[`withSafeAnimationFrame display name should wrap display name in non-production env 1`] = ` diff --git a/packages/safe-timers/test/__snapshots__/withSafeIdleCallback.jsx.snap b/packages/safe-timers/test/__snapshots__/withSafeIdleCallback.jsx.snap index 4b7ae57..80828a0 100644 --- a/packages/safe-timers/test/__snapshots__/withSafeIdleCallback.jsx.snap +++ b/packages/safe-timers/test/__snapshots__/withSafeIdleCallback.jsx.snap @@ -1,12 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`withSafeIdleCallback display name should not wrap display name in production env 1`] = ` - - - -`; +exports[`withSafeIdleCallback display name should not wrap display name in production env 1`] = ``; exports[`withSafeIdleCallback display name should wrap display name in non-production env 1`] = ` diff --git a/packages/safe-timers/test/__snapshots__/withSafeInterval.jsx.snap b/packages/safe-timers/test/__snapshots__/withSafeInterval.jsx.snap index 6a6a16b..dc8d2f1 100644 --- a/packages/safe-timers/test/__snapshots__/withSafeInterval.jsx.snap +++ b/packages/safe-timers/test/__snapshots__/withSafeInterval.jsx.snap @@ -1,12 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`withSafeInterval display name should not wrap display name in production env 1`] = ` - - - -`; +exports[`withSafeInterval display name should not wrap display name in production env 1`] = ``; exports[`withSafeInterval display name should wrap display name in non-production env 1`] = ` diff --git a/packages/safe-timers/test/__snapshots__/withSafeTimeout.jsx.snap b/packages/safe-timers/test/__snapshots__/withSafeTimeout.jsx.snap index 1de20fa..99ff963 100644 --- a/packages/safe-timers/test/__snapshots__/withSafeTimeout.jsx.snap +++ b/packages/safe-timers/test/__snapshots__/withSafeTimeout.jsx.snap @@ -1,12 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`withSafeTimeout display name should not wrap display name in production env 1`] = ` - - - -`; +exports[`withSafeTimeout display name should not wrap display name in production env 1`] = ``; exports[`withSafeTimeout display name should wrap display name in non-production env 1`] = `