Commit Graph

111 Commits

Author SHA1 Message Date
CommitSyncScript 76ec746341 Require Statement Nits 2013-06-24 16:16:38 -07:00
CommitSyncScript 14102e8a48 Fix isMounted() for composite components
This behavior seemed incorrect for composite components.

- isComponentMounted() represents ReactComponent's lifecycle of mounting
- isMounted() represents ReactCompositeComponent's lifecycle of isMounted()

Therefore, ReactComponents no longer have isMounted(). I think this is fine since it was not supposed to be public anyway.
2013-06-24 16:15:49 -07:00
CommitSyncScript 4f2d8dfe72 Dynamic Input Component
Summary:
This is a proposal based loosely on the discussions I've had with @paulshen and @jwalke. It implements a shim for `React.DOM.input` (used as `<input>`) that supports two different use cases depending on whether `value` is provided or not.

If a `value` is //not// provided, the input will be initialized with the empty string (or `defaultValue`) and anytime the user changes the input, the `onChange` (or `onTextChange`) handler will be fired and the DOM will reflect the new changes.

  React.renderComponent(
    <input type="text" defaultValue="Untitled" onTextChange={handleChange} />,
    container
  );

If a `value` is provided, the input will be initialized to that value. Anytime the user changes the input, the `onChange` (or `onTextChange`) handler will be fired. However, the DOM will //not// reflect the new changes. If a `value` is provided, it is the responsibility of the owner to update the `value` prop passed in.

  var value = "Untitled";
  var input = React.renderComponent(
    <input type="text" value={value} onTextChange={handleChange} />,
    container
  );
  function handleChange(event) {
    // Do something cool like strip out non-numbers.
    var value = event.target.value.replace(/\D/g, '');
    input.setProps({value: value});
  }

This is just a start and we should build similar components for `textarea` and `select`. Also, this does not inject the new components because the changes are not backward compatible. Once we change all `<input>` uses to use `ReactDOMInput`, then we can inject.
2013-06-24 16:13:14 -07:00
CommitSyncScript 7c60bb3e54 Add unit test to prevent regression
The original autobinding diff made some assumptions about how methods were called on components that had to be reverted. This diff
enforces those assumptions in a test
2013-06-24 16:12:06 -07:00
CommitSyncScript a62686622b Clean up naming
Fix a small style nit
2013-06-24 16:11:55 -07:00
CommitSyncScript a61f4df0b9 Fix a bunch of problems with implicit autobinding 2013-06-24 16:11:24 -07:00
CommitSyncScript 3266818b42 fix bad caching in ReactID.getID 2013-06-24 16:11:00 -07:00
CommitSyncScript c9ecbaccb3 Use React.autoBind by default.
Per our discussion - this is the general approach we'd like to take for
the public facing API.

    var MyComponent = React.createClass({
      render: function() {
        return <div onClick={this.myCallback} />;
      },
      myCallback: function() {
      }
    });
2013-06-24 16:10:33 -07:00
CommitSyncScript 3373572e15 Use ReactID.{get,set}ID instead of manipulating .id property directly.
Another step in the plan to centralize control of React-specific identifers.
2013-06-21 16:08:07 -07:00
CommitSyncScript 1839bcf109 Replace uses of ReactDOMNodeCache and getDOMNodeID with ReactID.
Also removed some unnecessary calls to `document.getElementById`, which
will eventually cease to work for React-specific IDs.

This clears the way for the deprecation of `ReactDOMNodeCache` and
`getDOMNodeID`.
2013-06-21 16:07:51 -07:00
CommitSyncScript 191c0dec32 Consolidate ReactDOMNodeCache and getDOMNodeID into ReactID.
When we move away from using the "id" attribute to identify
React-generated elements, we will need the cache (formerly
ReactDOMNodeCache) to be tied much more closely to the code that looks
elements up by ID (getDOMNodeID) and sets element IDs, since the magic of
document.getElementById will no longer be available.

The priming functions are going to come in handy when we create new DOM
fragments in mountComponent.

For backwards compatibility, the ReactDOMNodeCache and getDOMNodeID
modules still exist, but they are implemented entirely in terms of
functions exported from ReactID.
2013-06-21 16:07:22 -07:00
CommitSyncScript 2bc2b52eaa Allow accessing siblings by ref
This makes it possible to write a wider range of components without
depending on internal implementations.
2013-06-21 16:02:57 -07:00
CommitSyncScript 36a724feca Add reactComponentExpect#toBeComponentOfType
This adds a `toBeComponentOfType` method to `reactComponentExpect`. Now that we are injecting composite native components, `toBeDOMComponentWithTag` will not suffice and should be deprecated.
2013-06-21 16:02:55 -07:00
Paul O’Shannessy 4c97ffee34 Bring in Facebook's requestAnimationFrame module 2013-06-20 16:51:21 -07:00
CommitSyncScript 0e91febb9c Better warnings for missing keys on arrays
We have less dynamic arrays in the code base now so let's start warning for all
the cases where we pass dynamic arrays without keys.

I use the displayName to point out which component's render method was
responsible. I only warn once per component. If the child was created in a
different component (and passed as a property) I also show the owner of the
child. Maybe it should've attached the key at a higher level.

This does give false positives for arrays that are truly static. Those should
probably be refactored to use the XML syntax if possible.
2013-06-18 09:36:24 -07:00
CommitSyncScript 37ddfa0521 Don't transfer children in transferPropsTo
06cff60bc1 made it so that `this.props.children` was no longer set when
none were provided.

  var x = <div />;

This caused an issue if the code was relying on the following not
transferring children.

  return this.transferPropsTo(<div />);
  // this now transfer children
2013-06-18 09:32:23 -07:00
CommitSyncScript 3156458041 Fix most lint warnings/errors 2013-06-17 16:26:56 -07:00
CommitSyncScript 48333acba6 Remove reactKeys
It wasn't being used and it wasn't conforming to the @providesModule === file name rule.
2013-06-17 16:26:45 -07:00
CommitSyncScript 4a0456fb8e Fix lint warning about mismatched file & module name
@providesModule should match the file name. In this case we'll be consistent and suffix mixins with Mixin.
2013-06-17 16:26:07 -07:00
CommitSyncScript d8b6d260c9 Add missing license header 2013-06-17 12:50:55 -07:00
CommitSyncScript 6a41ede2d4 Fixing known keying problems
This fixes the last known parts of the flattening experiment. This has grown to
be somewhat complex and potentially fragile because of it. We may end up
reverting flattening in the future or address it slightly differently.

The purpose of this diff is to test if we've finally understood the real world
edge cases that flattening can lead to and how we have to key components to
cover those cases.

With this commit we never rekey the internal _key property. The semantics is
that once a component passes through a composite component, it's identity is
frozen.

props.key should accept numeric values and booleans which includes 0 and false.
This fixes the truthiness check.

We should never warn about missing key properties if a component is passed as a
static child. The _key acts as a flag to determine whether this component
was checked already.
2013-06-17 12:50:29 -07:00
CommitSyncScript c04081bc56 Add missing license header. 2013-06-17 12:50:15 -07:00
CommitSyncScript 0b1ecd8872 Add Back DOMCharacterDataModified
Accidentally lost `DOMCharacterDataModified`.
2013-06-17 12:49:58 -07:00
CommitSyncScript 88e90d5601 Use Synthetic Events
Swaps out usage of `AbstractEvent` with `SyntheticEvent` (and subclasses).
2013-06-17 12:49:45 -07:00
CommitSyncScript 03464dc148 Fix EventPluginRegistry Unit Tests in GitHub
Dumping the mock cache isn't dirying the modules in the open source version, so we have to unit test a different way. If we can fix the unit test framework, we should revert this.

Also, I added strict mode to `EventPluginRegistry.js`.

See: https://github.com/facebook/react/pull/91
2013-06-17 12:49:22 -07:00
CommitSyncScript 1112f1a003 React onlyChild utility.
Small utility that extracts and validates that there is only a single
child passed to a React composite component. The benefit here is that we
abstract away *how* the children are actually stored while we iterate on
different approaches. This way we won't break callsites as we try different
ideas. When we settle on a final approach, all of these callsites will still
work.
2013-06-17 12:48:47 -07:00
Paul O’Shannessy c1576fcf97 Remove trailing whitespace 2013-06-17 12:48:43 -07:00
CommitSyncScript 8592eacbf9 Use Node Cache in ReactComponent
There are currently two places where we lookup and cache nodes: `ReactDOMNodeCache` and `ReactComponent`. Instead, we should just consolidate caches and make `ReactComponent` use `ReactDOMNodeCache`.
2013-06-17 12:48:26 -07:00
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