playground version 0.0002

This commit is contained in:
avim 2014-11-16 18:20:43 +02:00
parent 44703b6600
commit 8b1f076856
4 changed files with 577 additions and 307 deletions

File diff suppressed because one or more lines are too long

View File

@ -27,26 +27,59 @@ function generateTemplateFunction(html) {
} catch (e) {
return emptyFunc
}
}
function generateRenderFunc(renderFunc) {
return function() {
var res = null;
try {
res = renderFunc.apply(this)
} catch (e) {
}
return React.DOM.div.apply(this, _.flatten([
{},
res
]));
}
}
var z = {getInitialState: function() {return {name:"reactTemplates"}}};
var Playground = React.createClass({
displayName: 'Playground',
mixins: [React.addons.LinkedStateMixin],
updateSample: function (state) {
this.sampleFunc = generateTemplateFunction(state.templateHTML);
this.sampleRender = generateRenderFunc(this.sampleFunc);
var classBase = {};
try {
console.log(state.templateProps);
classBase = eval("("+state.templateProps+")");
/*if (typeof classBase !== 'Object') {
throw "failed to eval";
}*/
} catch (e) {
classBase = {};
}
classBase.render = this.sampleRender;
console.log(classBase);
this.sample = React.createClass(classBase);
},
getInitialState: function () {
var currentState = {
templateHTML: '<div>\n hello {this.state.name}\n</div>',
templateProps: JSON.stringify({name:"reactTemplates"})
templateProps: '{getInitialState: function () {return {name:"reactTemplates"}}}'
};
this.templateFunc = generateTemplateFunction(currentState.templateHTML);
console.log(this.templateFunc);
this.updateSample(currentState);
return currentState;
},
componentWillUpdate: function (nextProps,nextState) {
if (nextState.templateHTML !== this.state.templateHTML) {
this.templateFunc = generateTemplateFunction(nextState.templateHTML)
if (nextState.templateHTML !== this.state.templateHTML || nextState.templateProps !== this.state.templateProps) {
this.updateSample(nextState);
}
},

View File

@ -5,7 +5,7 @@
<br/>
<textarea valueLink="{this.linkState('templateProps')}" class="large-text-area"></textarea>
</form>
<PlaygroundSample renderFunc="{this.templateFunc}" stateString="{this.state.templateProps}">
<this.sample>
</PlaygroundSample>
</this.sample>
</div>

View File

@ -9,8 +9,5 @@ module.exports = function () {
}), React.DOM.br({}), React.DOM.textarea({
'valueLink': this.linkState('templateProps'),
'className': 'large-text-area'
})), PlaygroundSample({
'renderFunc': this.templateFunc,
'stateString': this.state.templateProps
}));
})), this.sample({}));
};