@samitouri / QOS-React-2 / commits / f3e774559f

adding warning about the lack of support for onScroll on IE8

Adding `console.warn` about the lack of support for `onScroll` event on IE8 Related to this issue on github https://github.com/facebook/react/issues/631

Fabio Costa committed Jan 2, 2014 at 18:28 UTC f3e774559f5cfbcd45b5f3898eb85c28200cccdb
2 files changed +55
src/event/CallbackRegistry.js
+10
@@ -19,6 +19,8 @@
19
20 "use strict";
21
22 +var isEventSupported = require('isEventSupported');
23 +
24 var listenerBank = {};
25
26 /**
@@ -40,6 +42,14 @@ var CallbackRegistry = {
42 * @param {?function} listener The callback to store.
43 */
44 putListener: function(id, registrationName, listener) {
45 + if (__DEV__) {
46 + // IE8 has no API for event capturing and the `onScroll` event doesn't
47 + // bubble.
48 + if (registrationName === 'onScroll' &&
49 + !isEventSupported('scroll', true)) {
50 + console.warn('This browser doesn\'t support the `onScroll` event');
51 + }
52 + }
53 var bankForRegistrationName =
54 listenerBank[registrationName] || (listenerBank[registrationName] = {});
55 bankForRegistrationName[id] = listener;
src/event/__tests__/CallbackRegistry-test.js new
+45
@@ -0,0 +1,45 @@
1 +/**
2 + * Copyright 2013 Facebook, Inc.
3 + *
4 + * Licensed under the Apache License, Version 2.0 (the "License");
5 + * you may not use this file except in compliance with the License.
6 + * You may obtain a copy of the License at
7 + *
8 + * http://www.apache.org/licenses/LICENSE-2.0
9 + *
10 + * Unless required by applicable law or agreed to in writing, software
11 + * distributed under the License is distributed on an "AS IS" BASIS,
12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 + * See the License for the specific language governing permissions and
14 + * limitations under the License.
15 + *
16 + * @emails react-core
17 + */
18 +
19 +"use strict";
20 +
21 +require('mock-modules')
22 + .dontMock('CallbackRegistry')
23 + .mock('isEventSupported');
24 +
25 +describe('CallbackRegistry', function() {
26 + var CallbackRegistry;
27 + var isEventSupported;
28 +
29 + beforeEach(function() {
30 + require('mock-modules').dumpCache();
31 + CallbackRegistry = require('CallbackRegistry');
32 + isEventSupported = require('isEventSupported');
33 + isEventSupported.mockReturnValue(false);
34 + });
35 +
36 + it('should warn about the `onScroll` issue on IE8', function() {
37 + spyOn(console, 'warn');
38 + CallbackRegistry.putListener(1, 'onScroll', function(){});
39 + expect(console.warn.callCount).toBe(1);
40 + expect(console.warn.mostRecentCall.args[0]).toBe(
41 + 'This browser doesn\'t support the `onScroll` event'
42 + );
43 + });
44 +
45 +});