Commit Graph

66 Commits

Author SHA1 Message Date
Paul O’Shannessy 8cf5882447 Merge pull request #1021 from spicyj/close-finally
Set isInTransaction to false even if close throws
2014-02-11 09:27:09 -08:00
Cheng Lou 9ae002503c Ensure a pooled class releases back into the pool an instance of that class
Also added tests for PooledClass.

Noticed that some places use `ReactReconcileTransaction.release(transaction)`, when `transaction` might be of another class, say `ReactServerRenderingTransaction` (still a Github PR). This catches that.
2014-02-07 13:51:14 -08:00
Pete Hunt 9730759322 Fix cloneWithProps() to allow overriding props
This is a clear bug.
2014-02-04 14:37:53 -08:00
Ben Alpert 17f602f924 Set isInTransaction to false even if close throws
If a transaction wrapper's closer throws (such as flushBatchedUpdates in ReactDefaultBatchingStrategy) then we still want to properly deinitialize the transaction by setting isInTransaction to false. Without this, we can't reuse the transaction object (in this case, all future batched updates would fail because nested transactions aren't allowed).
2014-02-04 12:03:29 -08:00
Paul O’Shannessy 19ff353fdd Merge pull request #975 from spicyj/transaction-no-catch
Refactor Transaction to not rethrow errors
2014-02-03 21:43:27 -08:00
Cheng Lou 57bf7d21f3 fix transaction comment from componentDidRender to componentDidUpdate 2014-02-03 12:52:36 -08:00
Pete Hunt 4cbc4b58f6 Support children and ref for cloneWithProps()
We're not handling these correctly.
2014-01-30 16:53:47 -08:00
Ben Alpert d300df51e1 Refactor Transaction to not rethrow errors
Rethrowing errors makes debugging harder. This makes it so that an exception in a render method can be caught using the purple stop sign (or the blue one, of course) in Chrome.
2014-01-26 15:51:37 -08:00
Paul Shen 4a5a6ad733 Transfer the key prop in cloneWithProps
`cloneWithProps` uses `ReactPropTransferer`, which ignores the `key`
prop. See https://github.com/facebook/react/pull/713

However, this is not the case with `cloneWithProps` because when someone
is cloning a component and provides a key, they mean for the clone to
take it.
2014-01-23 13:48:39 -08:00
Paul O’Shannessy 1d1a790df0 Merge pull request #901 from syranide/80chars
Fix lines longer than 80 chars
2014-01-21 17:09:24 -08:00
Andreas Svensson 559cd46181 Shortened generated "data-reactid" 2014-01-20 22:03:25 +01:00
Andreas Svensson fd02f2c1cd Fix lines longer than 80 chars 2014-01-15 15:19:14 +01:00
Pete Hunt 1e980a146f Fix bug in cloneWithProps() 2014-01-06 18:35:54 -08:00
Sebastian Markbåge 4f09a54a1d Merge pull request #741 from spicyj/flatten-nonull
Don't return null children from flattenChildren
2014-01-06 16:21:34 -08:00
Pete Hunt cc005668b5 cloneWithProps()
what if you want to change the props of a child? This is my first attempt which lets you clone a child and transfer some custom props to it.

There is a fundamental issue with refs here. Since the component is cloned the ref will be broken. And since we can clone multiple times, it might not make sense to support repairing refs.
2014-01-02 19:46:50 -08:00
Ben Alpert e1ec9a6c65 Don't return null children from flattenChildren
This simplifies ReactMultiChild a little bit and will make it more practical to coalesce adjacent text strings.
2013-12-29 12:19:10 -07:00
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