Skip to content

Fix module-level reference to "window" #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/React/Basic/DOM/Components/GlobalEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,11 @@ GlobalEvent.prototype.render = function() {
};

exports.globalEvent_ = GlobalEvent;

exports.unsafeWindowEventTarget = (function() {
if (typeof window === "undefined") {
return undefined;
} else {
return window;
}
})();
7 changes: 3 additions & 4 deletions src/React/Basic/DOM/Components/GlobalEvents.purs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ import Prelude

import Data.Foldable (foldr)
import Effect (Effect)
import Effect.Unsafe (unsafePerformEffect)
import React.Basic (JSX, ReactComponent, element)
import Web.Event.Event (EventType)
import Web.Event.Internal.Types (Event, EventTarget)
import Web.HTML (window)
import Web.HTML.Window as Window

type EventHandlerOptions =
{ capture :: Boolean
Expand Down Expand Up @@ -100,7 +97,7 @@ windowEvents
}
-> JSX
-> JSX
windowEvents = globalEvents $ unsafePerformEffect $ map Window.toEventTarget window
windowEvents = globalEvents unsafeWindowEventTarget

windowEvent
:: { eventType :: EventType
Expand All @@ -111,6 +108,8 @@ windowEvent
-> JSX
windowEvent = windowEvents <<< pure

foreign import unsafeWindowEventTarget :: EventTarget

-- | Hide "unused ffi export" warning.
-- | The export is required to prevent
-- | PS' bundler from stripping it out.
Expand Down