.reactRoot[base10] -> .r[base36]

Just a bit of byte savings for server rendering. Props to @benjamn for the base36 idea (and for making this diff easy).

With a little work we could probably get rid of the .r as well.
This commit is contained in:
CommitSyncScript
2013-06-28 13:46:33 -07:00
committed by Paul O’Shannessy
parent 6556881417
commit 8bc2abd367
5 changed files with 21 additions and 21 deletions
+2 -2
View File
@@ -48,7 +48,7 @@ var GLOBAL_MOUNT_POINT_MAX = 9999999;
* @internal
*/
function getReactRootIDString(index) {
return '.reactRoot[' + index + ']';
return SEPARATOR + 'r[' + index.toString(36) + ']';
}
/**
@@ -316,7 +316,7 @@ var ReactInstanceHandles = {
* @internal
*/
getReactRootIDFromNodeID: function(id) {
var regexResult = /\.reactRoot\[[^\]]+\]/.exec(id);
var regexResult = /\.r\[[^\]]+\]/.exec(id);
return regexResult && regexResult[0];
},
+1 -1
View File
@@ -56,7 +56,7 @@ function getReactRootID(container) {
* ReactMount.renderComponent(component, $('container'));
*
* <div id="container"> <-- Supplied `container`.
* <div data-reactid=".reactRoot[3]"> <-- Rendered reactRoot of React
* <div data-reactid=".r[3]"> <-- Rendered reactRoot of React
* // ... component.
* </div>
* </div>
+13 -13
View File
@@ -34,7 +34,7 @@ describe('ReactIdentity', function() {
ReactID = require('ReactID');
});
var idExp = /^\.reactRoot\[\d+\](.*)$/;
var idExp = /^\.r\[.+?\](.*)$/;
function checkId(child, expectedId) {
var actual = idExp.exec(ReactID.getID(child));
var expected = idExp.exec(expectedId);
@@ -55,8 +55,8 @@ describe('ReactIdentity', function() {
React.renderComponent(instance, document.createElement('div'));
var node = instance.getDOMNode();
reactComponentExpect(instance).toBeDOMComponentWithChildCount(2);
checkId(node.childNodes[0], '.reactRoot[0].[0]{first}');
checkId(node.childNodes[1], '.reactRoot[0].[0]{second}');
checkId(node.childNodes[0], '.r[0].[0]{first}');
checkId(node.childNodes[1], '.r[0].[0]{second}');
});
it('should allow key property to express identity', function() {
@@ -71,10 +71,10 @@ describe('ReactIdentity', function() {
React.renderComponent(instance, document.createElement('div'));
var node = instance.getDOMNode();
reactComponentExpect(instance).toBeDOMComponentWithChildCount(4);
checkId(node.childNodes[0], '.reactRoot[0].[0:apple]');
checkId(node.childNodes[1], '.reactRoot[0].[0:banana]');
checkId(node.childNodes[2], '.reactRoot[0].[0:0]');
checkId(node.childNodes[3], '.reactRoot[0].[0:123]');
checkId(node.childNodes[0], '.r[0].[0:apple]');
checkId(node.childNodes[1], '.r[0].[0:banana]');
checkId(node.childNodes[2], '.r[0].[0:0]');
checkId(node.childNodes[3], '.r[0].[0:123]');
});
it('should use instance identity', function() {
@@ -95,15 +95,15 @@ describe('ReactIdentity', function() {
React.renderComponent(instance, document.createElement('div'));
var node = instance.getDOMNode();
reactComponentExpect(instance).toBeDOMComponentWithChildCount(3);
checkId(node.childNodes[0], '.reactRoot[0].[0:wrap1]');
checkId(node.childNodes[0], '.r[0].[0:wrap1]');
checkId(
node.childNodes[0].firstChild,
'.reactRoot[0].[0:wrap1].[0:squirrel]'
'.r[0].[0:wrap1].[0:squirrel]'
);
checkId(node.childNodes[1], '.reactRoot[0].[0:wrap2]');
checkId(node.childNodes[1].firstChild, '.reactRoot[0].[0:wrap2].[0:bunny]');
checkId(node.childNodes[2], '.reactRoot[0].[0:2]');
checkId(node.childNodes[2].firstChild, '.reactRoot[0].[0:2].[0:chipmunk]');
checkId(node.childNodes[1], '.r[0].[0:wrap2]');
checkId(node.childNodes[1].firstChild, '.r[0].[0:wrap2].[0:bunny]');
checkId(node.childNodes[2], '.r[0].[0:2]');
checkId(node.childNodes[2].firstChild, '.r[0].[0:2].[0:chipmunk]');
});
it('should let restructured components retain their uniqueness', function() {
@@ -149,8 +149,8 @@ describe('ReactInstanceHandles', function() {
describe('getReactRootIDFromNodeID', function() {
it('should support strings', function() {
var test = '.reactRoot[s_0_1][0]..[1]';
var expected = '.reactRoot[s_0_1]';
var test = '.r[s_0_1][0]..[1]';
var expected = '.r[s_0_1]';
var actual = ReactInstanceHandles.getReactRootIDFromNodeID(test);
expect(actual).toEqual(expected);
});
@@ -25,9 +25,9 @@ var ReactInstanceHandles;
var ResponderEventPlugin;
var SyntheticEvent;
var GRANDPARENT_ID = '.reactRoot[0]';
var PARENT_ID = '.reactRoot[0].0';
var CHILD_ID = '.reactRoot[0].0.0';
var GRANDPARENT_ID = '.r[0]';
var PARENT_ID = '.r[0].0';
var CHILD_ID = '.r[0].0.0';
var topLevelTypes;
var responderEventTypes;