Commit Graph

50 Commits

Author SHA1 Message Date
Christopher Chedeau fdf64919f3 Merge pull request #730 from syranide/lint80
Added max line length = 80 for jshint
2013-12-27 17:59:45 -08:00
Andreas Svensson a6b888b214 Escape component keys used in reactid 2013-12-28 01:58:59 +01:00
Andreas Svensson cbd6d8a46c Added max line length = 80 for jshint 2013-12-28 01:49:04 +01:00
Ben Alpert 30f566392b Extract out wrapUserProvidedKey for clarity 2013-12-25 22:32:43 -07:00
Ben Alpert 6fae670d19 Make shouldUpdateReactComponent key logic clearer
...and inline getComponentKey into traverseAllChildren.js.
2013-12-25 22:25:20 -07:00
Ben Alpert b0431a51ca Respect 'key' prop for object identity
Now when a `key` prop appears, its value is always honored. This means that in the root component or as an only child, changing key will cause remounting; in a `children` object, the `key` prop will be joined with the object key to form a two-part key.

Fixes #590.
2013-12-25 22:24:10 -07:00
Paul Shen 0fed861424 Move merge utility functions from utils to vendor/core 2013-11-05 17:17:47 -08:00
Paul O'Shannessy 46713c3d7d Fix Lint
Enabling bitwise linting caught another user. Also fixed a semicolon
misuse.
2013-10-15 17:59:14 -07:00
SanderSpies 5a13dd090d Standardize prop -> DOM attribute process
Allow more than strings and numbers to be used as attributes for DOM
nodes. This removes the special casing for `0` and `false` that was
being used in ReactDOMInput and ReactDOMTextarea.

Now we will just `toString` any object we try to insert into a DOM.

Closes #422, #372, #302
2013-10-15 11:38:25 -07:00
Josh Duck dbc613199b Fix SelectEventPlugin
There were 2 issues:

I was reusing event outside the original event handler (activeNativeEvent).
This is a bad idea. I've changed deferred dispatch to have an empty object
as the nativeEvent.

I didn't handle inputs without .selectionStart (e.g. file inputs). I extracted
a input type check from ChangeEventPlugin and reuse it here.
2013-10-08 10:28:43 -07:00
Josh Duck 2b7a7599bb Add select event plugin
Polyfill 'onSelect' behavior for React.

Use non-standard 'selectionchange' event rather than 'select' event.
This allows us to fire the event when user moves the cursor via arrow
keys, and not just when they select multiple chars.

Add methods to ReactDOMSelection to make getting current selection
easier, so we can do a fast check for change without having to
calculate char offsets for selection start and end.
2013-10-07 15:02:57 -07:00
Sebastian Markbage e5ba82a44b Fix DOM node warning
bdf2a9bb12 broke the warning that children aren't suppose to be real DOM nodes.
2013-09-17 16:04:44 -07:00
Tim Yung f88aa35187 Change vendored module isDOMNode -> isNode 2013-08-30 13:20:45 -07:00
Sebastian Markbage 61b38b9f05 Explicit and Implicit Keys Need Separate Namespaces
There are certain cases where you can end up with a collision with an implicit
key (array index) if your explicit key prop is a number. They should use
different namespaces. Therefore I wrap explicit keys in curlies and implicit
array indices in brackets.

I added a simple test case, but another case came up on the mailing list. Where
undefined entries in an array actually results in an entry and therefore an
implicit key.
2013-08-23 14:05:18 -07:00
Tim Yung 669f4b867f Allow DOM Nodes in ImmutableObject
Currently, `ImmutableObject` will stack overflow while it tries to recurse and deep freeze all the properties of a DOM node.
2013-08-19 11:37:08 -07:00
James Ide d9511d817a Move utils out of React that aren't being used
Many of React's util functions are non-redundant with Facebook's core
libraries, so move them out of React into a central location (out of
this repo).

These files were not getting used by any part of React core, so didn't
actually belong here anyway.
2013-08-16 15:40:11 -07:00
Paul Shen 9ef4e74ba2 ReactChildren
Instead of changing `traverseAllChildren`, keep that around for perf
reasons (for the hot code path `flattenChildren`)

Introduce `ReactChildren.map` and `ReactChildren.forEach`
which mirrors `Array.prototype.map` and `Array.prototype.forEach`. This
involves a rename of `mapAllChildren`
2013-08-06 14:17:33 -07:00
Tim Yung 2e37f65bdc Delete throwIf
Deletes `throwIf()` in favor of having one way to throw errors: `invariant()`
2013-07-26 12:48:07 -07:00
Tim Yung bdf2a9bb12 Use invariant in react/utils
Just some therapeutic cleanup.
2013-07-24 17:41:54 -07:00
Tim Yung 8d48610b7e Typecheck ImmutableObject
Just some therapeutic cleanup.
2013-07-24 17:41:37 -07:00
Tim Yung 759425fc90 Use invariant in OrderedMap
Just some therapeutic cleanup.
2013-07-24 17:41:22 -07:00
Pete Hunt 260d90ba02 Warn when server-rendered markup is not what we expect on the client
As @leebyron and balpert pointed out, if the markup on the server is differnet than what the client expects undefined behavior and chaos may ensue. A good fallback
is for us to just inject the client-side markup (as it is the source of truth) and warn the user in __DEV__ that something is wrong. In order to do a fast
browser-independent check of the DOM I use an adler32 checksum of the generated markup. I believe this is better than a simple innerHTML compare because different
browsers massage innerHTML differently.
2013-07-24 17:39:59 -07:00
Jordan Walke 492407bcc9 Fix OrderedMap.
Tim caught a bug. Squashing it so he can rebase on top of it.
2013-07-24 17:39:37 -07:00
Jordan Walke 5d4f903482 [React Children] Step Three: New test case for traverseChildren.
If we're going to build utilities off of this, we should have good test
coverage.
2013-07-16 11:36:53 -07:00
Jordan Walke 946029c921 [React Children] Step Two: Use traverseChildren to perform mapChildren
Use the new `traverseChildren` utility to perform `mapChildren`.
The goal is to get as close to the bavior of the semantics of
`Array.prototype.map`, but also in a way that understands deeply nested arrays
and objects.
2013-07-16 11:36:11 -07:00
Jordan Walke f4321f8624 [React Children] Step One: Refactor flattenChildren
Refactoring `flattenChildren` so that the traversal code is reusable
for other purposes.
2013-07-16 11:35:43 -07:00
Pete Hunt 5c624021ea Tweaks to make the Closure parser happy
This doesn't make it actually run with Closure, but passes its parser.
2013-07-08 11:50:02 -07:00
Sebastian Markbage d50148591b Introduce a supported way to slice children
Introduces a counterpart to mapChildren. It excludes empty children just as
mapChildren for compatibility. With might introduce something like
sliceChildrenIncludingEmptyValues at some point.
2013-07-02 18:30:04 -07:00
CommitSyncScript dd61439061 Revert Flattening of Children
I still think the semantics of flattening children is valid but we'll
want to revert the flattening implementation while we solidify the
semantics and try another approach.

This reverts flattening so that this.props.children can once again be
either a single child, flat array or nested array.

mapChildren calls flattenChildren before doing anything else. This is
not the most efficient approach but I wanted to keep this inital diff
simple. It also ignores empty values for backwards compatibility.

We may want to try another approach where empty values are included
in the map.

Validation of keys is still done inside ReactComponent. Ideally I'd
like to extract that into a separate module but to avoid cyclic
dependencies, I'm keeping it in ReactComponent for now.
2013-07-01 13:01:52 -07:00
CommitSyncScript 15272f30f4 Don't keep the HTML escaped ID internally, only in HTML generation
A dynamic value can be provided as a key to a child. Either as part of an object
or key property. This becomes part of the component's ID.

We have to be careful to escape this key before inserting it into the DOM since
it could become a vulnerability. We fixed this by escaping just the keys.

However, the current implementation breaks when you used escaped keys. The
internal value is escaped and the value used by getAttributeNode and
getElementById are both unescaped.

This fixes that by keeping the unescaped value internally but escaping it right
before the HTML is generated (like any other attribute).

This is important since business logic IDs (that should be used as keys)
contains characters that need to be escaped.
2013-06-28 16:35:45 -07:00
CommitSyncScript a9b024330c Make @typechecks static-only 2013-06-25 14:01:15 -07:00
CommitSyncScript de40842597 Use @return, not @returns 2013-06-24 16:16:46 -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 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 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
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 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 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
Paul O’Shannessy 83101b878e Add license headers to new files 2013-06-06 14:29:45 -07:00
CommitSyncScript b581c8cfc7 Always reassign _key for every pass
Currently we're mutating _key. Mutation here is fine, but it needs to
be idempotent - which it's not. This is causing some issues.

Instead I reassign the _key every time it passes through a flattening.
This means that it's unique and stable for a single pass through a composite
component. When it's repassed another level, it loses it previous
identity and is rekeyed by it's new location.

For auto-generated keys by index, this actually means it has the same
semantics as before flattening.

For explicit keys, it has the effect that keys need to be unique at
every level. Regardless of how the key got there. Every component needs to ensure
that it doesn't combine keys from two different sources that may collide. This
is also inline with the old semantics but less intuitive in the new model.
2013-06-06 14:29:44 -07:00
CommitSyncScript 259392035d mapChildren
mapChilden() is similar to Array.map() and objMap() but handles deep
nested structures and follows similar rules to flattenChildren()
2013-06-06 14:29:44 -07:00
CommitSyncScript 4b81de93d3 use key="foo" for all components
flattenChildren was only using key when child.mountInContainerNode
exists, which is defined on ReactCompositeComponent, and not
ReactNativeComponent.

This uses the isValidComponent() fn to see if we should use this key.
2013-06-06 14:29:44 -07:00
CommitSyncScript 007b75f78a Flatten Children A Single Level
This expects static children as additional arguments to the constructor
and flattens any array arguments one level deep.

Component(props, child1, child2, arrayOfChildren, child3) ->
.props.children = [child1, child2, ...arrayOfChildren, child3]

This can avoid an additional heap allocation for the unflat array.

It allows you to pass nested arrays and objects like you used to. Those
aren't immediately flattened. That makes this a fairly safe change.

Passing a dynamic array without key properties will yield a warning
(once). Might consider throwing later.

Once we change the transpiler to use the new syntax, you'll end up with
a single flat array in normal usage.

This doesn't actually update the JSX transform.
2013-06-06 14:29:43 -07:00
Ben Newman 42f8d155f8 Silence tests unsupported in PhantomJS.
These tests can still be run in the browser using `grunt test --debug`.
2013-06-03 13:20:13 -04:00
Paul O’Shannessy 75897c2dcd Initial public release 2013-05-29 12:54:02 -07:00