git.iko.soy/rowtype-yoga/yoga-r3f
on main help sign in
95 lines 2.0 kB history raw
1import React from "react";
2export var _passiveSupported = null;
4function checkPassiveSupported() {
5 if (_passiveSupported == null) {
6 try {
7 window.addEventListener(
8 "test",
9 null,
10 Object.defineProperty({}, "passive", {
11 get: function() {
12 _passiveSupported = true;
13 }
14 })
15 );
16 } catch (err) {
17 _passiveSupported = false;
18 }
19 }
20 return _passiveSupported;
23function createHandler(h) {
24 return function(e) {
25 return h(e)();
26 };
29function up(target, eventType, handler, options) {
30 target.addEventListener(
31 eventType,
32 handler,
33 checkPassiveSupported() ? options : options.capture
34 );
37function down(target, eventType, handler, options) {
38 target.removeEventListener(
39 eventType,
40 handler,
41 checkPassiveSupported() ? options : options.capture
42 );
45var GlobalEvent = function() {
46 return this;
47};
49GlobalEvent.prototype = Object.create(React.Component.prototype);
51GlobalEvent.displayName = "GlobalEvent";
53GlobalEvent.prototype.componentDidMount = function() {
54 this._handler = createHandler(this.props.handler);
55 up(
56 this.props.target,
57 this.props.eventType,
58 this._handler,
59 this.props.options
60 );
61};
63GlobalEvent.prototype.componentDidUpdate = function(prevProps) {
64 down(prevProps.target, prevProps.eventType, this._handler, prevProps.options);
65 this._handler = createHandler(this.props.handler);
66 up(
67 this.props.target,
68 this.props.eventType,
69 this._handler,
70 this.props.options
71 );
72};
74GlobalEvent.prototype.componentWillUnmount = function() {
75 down(
76 this.props.target,
77 this.props.eventType,
78 this._handler,
79 this.props.options
80 );
81};
83GlobalEvent.prototype.render = function() {
84 return this.props.child;
85};
87export {GlobalEvent as globalEvent_};
89export var unsafeWindowEventTarget = (function() {
90 if (typeof window === "undefined") {
91 return undefined;
92 } else {
93 return window;
94 }
95})();