React Base Fiddle (JSX)
Starting point for creating JSFiddles with React. This uses React with Addons.
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.1/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.1/react-with-addons.js"></script>
<script src="https://facebook.github.io/react/js/jsfiddle-integration.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
JavaScript 1.7
'use strict';
var reactRootStoreNextPropertyIndex = 0;
function getRootStoreData(instance) {
var rootStoreProvider = instance.context.__rootStoreProviderInstance;
if (rootStoreProvider) {
return rootStoreProvider.data;
}
if (!('__rootStoreProviderInstance' in instance.context)) {
throw new Error("instance does not have context");
}
throw new Error("context provider not available");
}
function ReactRootStoreProperty(defaultValue) {
this.propertyIndex = reactRootStoreNextPropertyIndex++;
this.defaultValue = defaultValue;
}
ReactRootStoreProperty.prototype.get = function(instance) {
var propertyIndex = this.propertyIndex;
var rootStoreData = getRootStoreData(instance);
if (propertyIndex in rootStoreData) {
return rootStoreData[propertyIndex];
}
var propertyDefaultValue = this.defaultValue;
var propertyDefaultValueType = typeof propertyDefaultValue;
var actualDefaultValue = propertyDefaultValue;
if (propertyDefaultValueType === 'function') {
actualDefaultValue = propertyDefaultValue();
} else if (propertyDefaultValueType === 'object' && propertyDefaultValue !== null) {
throw new Error('objects cannot be default values, use a function');
}
return rootStoreData[propertyIndex] = actualDefaultValue;
};
ReactRootStoreProperty.prototype.set = function(instance, value) {
var rootStoreData = getRootStoreData(instance);
rootStoreData[this.propertyIndex] = value;
};
/** @constructor */
function ReactRootStoreProvider(props) {
React.Component.call(this, props);
this.data = {};
}
ReactRootStoreProvider.prototype = Object.create(React.Component.prototype);
ReactRootStoreProvider.prototype.constructor = ReactRootStoreProvider;
ReactRootStoreProvider.childContextTypes = {
__rootStoreProviderInstance: React.PropTypes.any
};
ReactRootStoreProvider.prototype.getChildContext = function() {
return {
__rootStoreProviderInstance: this
};
};
ReactRootStoreProvider.prototype.render = function() {
...