Commit Graph

83 Commits

Author SHA1 Message Date
Timothy Yung c7295b9e09 Merge pull request #61 from spicyj/getdomnodeid
getDOMNodeID: Don't return .id on random objects
2013-06-14 11:27:44 -07:00
Ben Newman 9fd9f712bf Merge pull request #91 from yungsters/master
Fix `EventPluginRegistry` Unit Tests
2013-06-14 06:45:57 -07:00
Ben Alpert a9c70bcc1c getDOMNodeID: Don't return .id on random objects
If you defined a global named `id` (a horrible name, I know) then
getDOMNodeID(window) would return that object. Since only DOM nodes can
have IDs, this should be a noop change otherwise.

Test Plan:
Verified that document.documentElement and document.body both support
getAttributeNode properly in latest Chrome and in IE8.
2013-06-14 00:21:15 -07:00
Timothy Yung 80edd6ca87 Merge pull request #89 from vjeux/patch-4
Exposing ReactProps as React.Props
2013-06-13 21:08:10 -07:00
yungsters 279792f891 Fix EventPluginRegistry Unit Tests
Dumping the mock cache isn't dirying the modules, so we have to unit test a different way. If we can fix our unit test framework, we should revert this.

Also, I added strict mode to `EventPluginRegistry.js`.
2013-06-13 20:38:23 -07:00
Ben Alpert 792b69ba11 Fix textchange event enqueueing
(Was broken by e1535fbd71d8c89c82cd9d9073c1ee97ee6a3b00.)
2013-06-13 20:34:14 -07:00
CommitSyncScript 770ec5946a Unbreaking falsy check on style values
Style values can be the number zero which is an actual value. So we check for
null instead. The empty string case falls through.
2013-06-13 17:49:04 -07:00
CommitSyncScript b525a0c061 Unnecessary this._rootNodeID Invariant
Summary: This invariant is unnecessary because `ReactComponent.Mixin.receiveProps` already asserts that this component is mounted. (Being mounted guarantees you have a DOM ID, look at `ReactComponent` and see when `this._rootNodeID` is mutated.)
2013-06-13 17:48:09 -07:00
CommitSyncScript 34970fd785 Fix tht typos 2013-06-13 17:47:59 -07:00
Paul O’Shannessy ceb5303581 Merge pull 75 upstream
Needed to make some small changes since we weren't synced when it was
merged.
2013-06-13 17:47:51 -07:00
CommitSyncScript f456f8fa8d Remove isStatic
This can be replicated with a custom component that always returns false`
from `shouldComponentUpdate`. A generic implementation might look like:

```
var StaticContainer = React.createClass({
  shouldComponentUpdate: function() {
    return false;
  },

  render: function() {
    return this.transferPropsTo(this.props.children[0]);
  }
});
```

And then used in JSX as
`<StaticContainer><div>Hello!</div></StaticContainer>`, resulting in
only `<div>Hello!</div>` being inserted into the DOM.
2013-06-13 17:40:52 -07:00
CommitSyncScript e1fe13d0cb Pass multiple children in JSX as additional arguments
This is an alternative to D809298. In normal usage you'd end up with a single
flat array in props.children.
2013-06-13 17:40:05 -07:00
CommitSyncScript 01511ea557 Remove Unnecessary DOM Mutations
This fixes an edge case that can cause unnecessary mutations in the DOM. Namely, if a prop is falsey, it will get touched on every update by reconciliation. See unit test.
2013-06-13 17:39:47 -07:00
CommitSyncScript 802241a660 Cleanup style Prop Reconciliation
This cleans up the reconcilation path when adding a `style` prop (going from a falsey or no `style` to having one) by reducing the need for an object allocation and for-loop.
2013-06-13 17:39:23 -07:00
CommitSyncScript e1535fbd71 Create EventPluginRegistry
The `EventPluginHub` module was getting huge and scary. This pulls out all of the logic required to inject plugins and publish their event registration names into a new `EventPluginRegistry` module.

Functionally, nothing should have changed. I added many error checks to cover edge cases that we were not yet running into, but they are all in `EventPluginRegistry` and unit tested.
2013-06-13 17:38:49 -07:00
CommitSyncScript aea8e16b4a Add ReactComponent#isMounted
There is currently no way for components to know whether or not they are mounted. This means there's no way for callbacks to figure out if they can make certain assumptions (e.g. can `getDOMNode()` or `setState()` be safely invoked).

This adds an `isMounted` protected method that lets components properly handle callback behavior when unmounted.
2013-06-13 17:38:20 -07:00
CommitSyncScript 0d6bb650cb Add HTML5 Drag/Drop events to React 2013-06-13 17:37:58 -07:00
Christopher Chedeau 34173638d4 Exposing ReactProps as React.Props
Right now, even though ReactProps is committed, there is no way to use it as it is not exposed.
2013-06-12 18:28:25 -06:00
Timothy Yung dfd76be568 Merge pull request #75 from spicyj/textchange
Add new textChange event: input + IE shim
2013-06-11 22:00:19 -07:00
Ben Alpert 0dc08c2115 Missing semicolon 2013-06-11 21:54:50 -07:00
Ben Alpert 6b572b3f25 Refactor based on review feedback 2013-06-11 21:51:47 -07:00
Timothy Yung c6c40a5fb3 Merge pull request #84 from spicyj/remove-props
Correctly remove attributes when deleting props
2013-06-11 19:54:36 -07:00
Ben Alpert fdc6beed1a Fix nit and comment 2013-06-11 19:53:24 -07:00
Ben Alpert 731aa8ead1 internalPropNames isn't necessary, so remove it
Perhaps we'll bring it back as a future perf optimization if that
appears useful.
2013-06-11 19:02:35 -07:00
Ben Alpert 8762634cf1 Remove unused require 2013-06-11 17:28:06 -07:00
Ben Alpert 735a91c9d5 Fix relative require copy pasta 2013-06-11 17:24:35 -07:00
Ben Alpert 705ce56694 Correctly remove attributes when deleting props
The most obvious manifestation of this bug is visible here:
http://jsfiddle.net/spicyj/zzGas/. In short, when props are removed from a
component, the underlying HTML element doesn't have the attribute
removed.

This change should fix it, but unfortunately it (presumably) makes
_updateDOMProperties a bit slower.
2013-06-11 16:46:10 -07:00
Paul O’Shannessy 758c21fb9c Merge pull request #77 from spicyj/componentdidmount-order
Run inner componentDidMount method first
2013-06-11 13:10:03 -07:00
Ben Alpert 932c45a7ab Check canUseDOM before calling isEventSupported 2013-06-10 18:27:22 -07:00
Ben Alpert e39743f2f8 Removed unused variable 2013-06-10 17:19:45 -07:00
Paul O’Shannessy cff4d53a9e Add missing license headers 2013-06-10 16:25:37 -07:00
CommitSyncScript c2ce1d00cd Fix Event Normalization in IE<9
IE<9 relied on the `target` property being overriden. This adds back a hack that only applies in IE<9. I'll be able to revert this hack once I check in synthetic events.
2013-06-10 16:19:25 -07:00
CommitSyncScript b3e0dc47a8 Rename "Delegate" to "Synthetic"
This is just a simple rename of the event classes to `SyntheticEvent`. I've also updated the constructor arguments to be more correct:

 - `dispatchConfig`: Data used by the plugin system for dispatching the event, for example: `{registrationName: 'onClick'}`
 - `dispatchMarker`: An identifying marker used to describe where the event is occuring, for example: `.reactRoot[0]`
2013-06-10 16:19:03 -07:00
CommitSyncScript 93f979ae18 Use isAncestorIDOf in ReactInstanceHandles
This is both a functional fix and performance fix for `ReactInstanceHandles`.

 - `getFirstReactDOM` uses `indexOf` but should be checking ancestry (via `isMarker()`).
 - Added `isAncestorIDOf`, checking ancestry can be way faster than getting a common ancestor: http://jsperf.com/react-ancestor-id-check
2013-06-10 16:18:40 -07:00
CommitSyncScript ca3f871646 Reduce ReactInstanceHandles API Surface Area
Change `ReactInstanceHandles` so that `getFirstCommonAncestorID` and `nextDescendantID` are now private (and documented to be only exposed for unit testing). Also:

 - Renamed `nextDescendantID` to `getNextDescendantID`.
 - Renamed `parentID` to `getParentID`.

I also organized `ReactInstanceHandles-test` by method names.

Functionally, this diff should not change anything.
2013-06-10 16:18:13 -07:00
CommitSyncScript 1be6c592a6 Fix typechecks for isRenderedByReact() 2013-06-10 16:17:52 -07:00
CommitSyncScript 37cde3d864 Stabilize minimal server rendering API
This is a pretty killer feature and the API is simple. I know it's another API method on React, but I think it's
the only way.
2013-06-10 16:17:26 -07:00
Ben Alpert 2afd7186ae Run inner componentDidMount method first
Fixes #76.
2013-06-09 17:21:22 -07:00
Ben Alpert c19bf9cffe Add new textChange event: input + IE shim
IE8 doesn't support oninput and IE9 supports it badly but we can do
almost a perfect shim by listening to a handful of different events
(focus, blur, propertychange, selectionchange, keyup, keydown).

This always triggers event handlers during the browser's event loop (not
later in a setTimeout) and after the value property has been updated.

The only case I know of where this doesn't fire the event immediately is
if (in IE8) you modify the input value using JS and then the user does a
key repeat, in which case we fire the event on the second keydown.

Test Plan:
Modify ballmer-peak example to add es5-shim and to use onTextChange
instead of onInput. In IE8, IE9, and latest Chrome, make sure that the
event is fired upon:

* typing normally,
* backspacing,
* forward-deleting,
* cutting,
* pasting,
* context-menu deleting,
* dragging text to reorder characters.

After modifying the example to change .value, make sure that the event
is not fired as a result of the changes from JS (even when the input box
is focused).
2013-06-09 04:18:15 -07:00
CommitSyncScript 7e7579e1ba Assign the same keys if it's a single nested array or not
If you specify a single array, we didn't prefix the keys with 0.

If you later add children, the first array won't have the same key.
2013-06-07 22:10:20 -07:00
CommitSyncScript 582359aeea Remove React.createComponentRenderer
Remove ReactMount.createComponentRenderer because it does not function
correctly.

  var f = React.createComponentRenderer(<div />);

  var container1 = document.createElement('div');
  var container2 = document.createElement('div');
  f(container1);
  f(container2); // error because mounting same instance into new root
2013-06-07 22:10:06 -07:00
CommitSyncScript 6c3c643c8e Fix typo in OrderedMap
Unique was spelled wrong. This fixes it.
2013-06-07 22:09:49 -07:00
CommitSyncScript 3eaed5a122 Delegate Event Classes
React's top-level event delegation dispatches `AbstractEvent` objects that contain:

 - `nativeEvent`, the original browser event.
 - `data`, an object with custom normalized properties.

This diff creates a set of `DelegateEvent` classes that will replace `AbstractEvent`. The goal is two-fold:

 # Provide a cross-browser implementation that conforms to the DOM Level 3 Events API so people don't have to use `nativeEvent`.
 # Generalize the event object API so that it can be shared by `DOMEventManager`, a top-level event delegation WIP.

This simply implements the classes. I will follow-up by replacing `AbstractEvent` with them.
2013-06-07 22:08:32 -07:00
CommitSyncScript 4bb966a7f0 Bugfixes to key assignment
Type coersion bug and ID breaking assumption.

Names need to be wrapped in something unique since otherwise two unique siblings
can end up having IDs that are subsets of eachother.
2013-06-07 22:08:14 -07:00
CommitSyncScript 0e9e64c550 Replace persistentCloneOf with persist
There are to reasons to prefer a `persist` method on the event rather than a static method:

 - In open source, people do not have access to `AbstractEvent`.
 - This will allow people to persist events without requiring another module.
 - This will make refactors easier and more flexible.
2013-06-07 22:07:43 -07:00
Paul O’Shannessy 59bee8df21 Remove clowny diff.diff
An artifact of our sync process.
2013-06-06 15:09:11 -07:00
CommitSyncScript 2dc24fc234 Add typecheck, cleanup
Followup with some additional comments for https://github.com/facebook/react/pull/58
2013-06-06 14:50:54 -07:00
CommitSyncScript 88923f61a7 Improve Browser Support for wheel Event
This improved browser support for the `wheel` event.

 - Try to use `wheel` event (DOM Level 3 Specification).
 - Fallback to `mousewheel` event.
 - Fallback to `DOMMouseWheel` (older Firefox).

Also, since `wheel` is the standard event name, let's use that in React.

NOTE: The tricky part was detecting if `wheel` is supported for IE9+ because `onwheel` does not exist.

Test Plan:
Execute the following in the console on a page with React:

  var React = require('React');
  React.renderComponent(React.DOM.div({
    style: {
      width: 10000,
      height: 10000
    },
    onWheel: function() {
      console.log('wheel');
    }
  }, null), document.body);

Verified that mousewheel events are logged to the console.
Verified in IE8-10, Firefox, Chrome, and Safari.
2013-06-06 14:48:25 -07:00
CommitSyncScript ba6fea1bf5 Simplify Event Core
Summary:
This makes a few changes to React Core, most notably `ReactEventEmitter` and `ReactEventTopLevelCallback`.

 - Changed `ReactEventEmitter` to use `EventListener` (instead of `NormalizedEventListener`).
 - Deleted `NormalizedEventListener` (which was previously broken).
 - Created `getEventTarget` which is used to get a normalized `target` from a native event.
 - Changed `ReactEventTopLevelCallback` to use `getEventTarget`.
 - Renamed `abstractEventType` to `reactEventType` in `AbstractEvent`.
 - Reanmed `abstractTargetID` to `reactTargetID` in `AbstractEvent`.
 - Removed `originatingTopLevelEventType` from `AbstractEvent` (unused and violates encapsulation).
 - Removed `nativeEvent.target === window` check when refreshing authoritative scroll values (unnecessary).

This actually fixes React because `NormalizedEventListener` does not currently do what it promises to do (which is normalizing `target` on the native event). The `target` event is read-only on native events.

This also revises documentation and adds `@typechecks` to a few modules.

NOTE: Most importantly, this sets the stage for replacing `AbstractEvent` with `ReactEvent` and subclasses, piecemeal.
2013-06-06 14:48:12 -07:00
CommitSyncScript 36d8ce8fab [React] remove deprecated Component.update()
Summary: Since grepping for `update` and `updateAll` is pretty hard, I had these these functions call through but complain loudly. This noisy call through has been in prod for over a week and I haven't heard any complains, so let's take it out altogether.
2013-06-06 14:46:53 -07:00