Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81165 views
1
/**
2
* Copyright 2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @providesModule LocalEventTrapMixin
10
*/
11
12
"use strict";
13
14
var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
15
16
var accumulateInto = require('accumulateInto');
17
var forEachAccumulated = require('forEachAccumulated');
18
var invariant = require('invariant');
19
20
function remove(event) {
21
event.remove();
22
}
23
24
var LocalEventTrapMixin = {
25
trapBubbledEvent(topLevelType, handlerBaseName) {
26
invariant(this.isMounted(), 'Must be mounted to trap events');
27
var listener = ReactBrowserEventEmitter.trapBubbledEvent(
28
topLevelType,
29
handlerBaseName,
30
this.getDOMNode()
31
);
32
this._localEventListeners =
33
accumulateInto(this._localEventListeners, listener);
34
},
35
36
// trapCapturedEvent would look nearly identical. We don't implement that
37
// method because it isn't currently needed.
38
39
componentWillUnmount() {
40
if (this._localEventListeners) {
41
forEachAccumulated(this._localEventListeners, remove);
42
}
43
}
44
};
45
46
module.exports = LocalEventTrapMixin;
47
48