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

Re-add with warning and monitorCodeUse

Charles Marsh committed Aug 14, 2014 at 10:11 UTC a195d3ea1ffd389e81b83b4ccdee277086f219e5
4 files changed +44 -8
docs/_config.yml
+1 -1
@@ -34,4 +34,4 @@ sass:
34 sass_dir: _css
35 gems:
36 - jekyll-redirect-from
37 -react_version: 0.12.0-alpha
37 +react_version: 0.11.1
docs/docs/ref-05-events.md
+4 -4
@@ -10,10 +10,6 @@ next: dom-differences.html
10
11 Your event handlers will be passed instances of `SyntheticEvent`, a cross-browser wrapper around the browser's native event. It has the same interface as the browser's native event, including `stopPropagation()` and `preventDefault()`, except the events work identically across all browsers.
12
13 -> Note:
14 ->
15 -> Prior to v0.12, event handlers could return `false` to stop propagation. This behavior is no longer supported; instead, `stopPropagation()` and `preventDefault()` should be triggered manually.
16 -
13 If you find that you need the underlying browser event for some reason, simply use the `nativeEvent` attribute to get it. Every `SyntheticEvent` object has the following attributes:
14
15 ```javascript
@@ -31,6 +27,10 @@ Date timeStamp
27 String type
28 ```
29
30 +> Note:
31 +>
32 +> As of v0.12, returning `false` from an event handler will no longer stop event propagation. Instead, `stopPropagation()` and `preventDefault()` should be triggered manually.
33 +
34
35 ## Supported Events
36
src/browser/__tests__/ReactBrowserEventEmitter-test.js
+14 -3
@@ -253,7 +253,7 @@ describe('ReactBrowserEventEmitter', function() {
253 expect(idCallOrder[0]).toBe(getID(CHILD));
254 });
255
256 - it('should continue to propagate if false is returned', function() {
256 + it('should stopPropagation if false is returned, but warn', function() {
257 ReactBrowserEventEmitter.putListener(
258 getID(CHILD),
259 ON_CLICK_KEY,
@@ -264,10 +264,21 @@ describe('ReactBrowserEventEmitter', function() {
264 ON_CLICK_KEY,
265 recordID.bind(null, getID(PARENT))
266 );
267 + ReactBrowserEventEmitter.putListener(
268 + getID(GRANDPARENT),
269 + ON_CLICK_KEY,
270 + recordID.bind(null, getID(GRANDPARENT))
271 + );
272 + spyOn(console, 'warn');
273 ReactTestUtils.Simulate.click(CHILD);
268 - expect(idCallOrder.length).toBe(2);
274 + expect(idCallOrder.length).toBe(1);
275 expect(idCallOrder[0]).toBe(getID(CHILD));
270 - expect(idCallOrder[1]).toBe(getID(PARENT));
276 + expect(console.warn.calls.length).toEqual(1);
277 + expect(console.warn.calls[0].args[0]).toBe(
278 + 'Returning `false` from an event handler will be deprecated in a ' +
279 + 'future release. Instead, manually call stopPropagation() and ' +
280 + 'preventDefault().'
281 + );
282 });
283
284 /**
src/browser/eventPlugins/SimpleEventPlugin.js
+25
@@ -34,6 +34,7 @@ var SyntheticWheelEvent = require('SyntheticWheelEvent');
34 var getEventCharCode = require('getEventCharCode');
35
36 var invariant = require('invariant');
37 +var monitorCodeUse = require('monitorCodeUse');
38 var keyOf = require('keyOf');
39
40 var topLevelTypes = EventConstants.topLevelTypes;
@@ -299,6 +300,30 @@ var SimpleEventPlugin = {
300
301 eventTypes: eventTypes,
302
303 + /**
304 + * Same as the default implementation, except cancels the event when return
305 + * value is false. This behavior will be disabled in a future release.
306 + *
307 + * @param {object} Event to be dispatched.
308 + * @param {function} Application-level callback.
309 + * @param {string} domID DOM ID to pass to the callback.
310 + */
311 + executeDispatch: function(event, listener, domID) {
312 + var returnValue = EventPluginUtils.executeDispatch(event, listener, domID);
313 + if (returnValue === false) {
314 + if (__DEV__) {
315 + monitorCodeUse('react_event_return_false');
316 + console.warn(
317 + 'Returning `false` from an event handler will be deprecated in a ' +
318 + 'future release. Instead, manually call stopPropagation() ' +
319 + 'and preventDefault().'
320 + );
321 + }
322 + event.stopPropagation();
323 + event.preventDefault();
324 + }
325 + },
326 +
327 /**
328 * @param {string} topLevelType Record from `EventConstants`.
329 * @param {DOMEventTarget} topLevelTarget The listening component root node.