Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jspears committed Dec 11, 2015
1 parent a4c6349 commit 70ebd1f
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 132 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"react-addons-test-utils": "^0.14.3",
"react-dom": "^0.14.3",
"react-hot-loader": "^1.3.0",
"react-router": "^1.0.2",
"source-map": "^0.5.3",
"source-map-support": "^0.4.0",
"strip-loader": "^0.1.0",
Expand Down
8 changes: 5 additions & 3 deletions public/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ loader.addType({
Main
});
loader.addTemplate({
NavListTemplate,
NavTemplate,
ULTemplate,
H3(props){
Expand Down Expand Up @@ -50,11 +49,14 @@ let unlisten = location.listen(location => {
valueManager.update('useError', location.query.useError);
})
function handleDataError(val, old, path) {
if (!val && loc.query[path] == 'true') {
if (val == null){
return;
}
if (!val && path in loc.query && loc.query[path] == 'true') {
delete loc.query[path];
location.push(loc);
} else {
if (loc.query[path] + '' != '' + val) {
if (val && loc.query[path] + '' != '' + val) {
loc.query[path] = val;
location.push(loc);
}
Expand Down
23 changes: 0 additions & 23 deletions public/components/Button.jsx

This file was deleted.

135 changes: 76 additions & 59 deletions public/components/Example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,67 @@
import React, {Component} from 'react';
import ReactDOM from 'react-dom';
import Highlight from './Highlight.jsx';
import Playground from 'component-playground/lib/components/playground.js';
//import Playground from 'component-playground/lib/components/playground.js';
import Subschema from 'Subschema';
import CodeMirror from 'codemirror/mode/javascript/javascript.js';
import cloneDeep from 'lodash/object/cloneDeep';
import cloneDeep from 'lodash/lang/cloneDeep';

var {PropTypes, Form, ValueManager, loaderFactory, DefaultLoader, decorators} = Subschema;
var {provide} = decorators;
var {provide, listen} = decorators;

function stringify(name, obj) {

var str = !obj ? 'null' : typeof obj === 'string' ? obj : JSON.stringify(obj, null, '\t');
return `var ${name} = ${str};`;
}
var {...contextTypes} = PropTypes.contextTypes;
contextTypes.schema = PropTypes.any;
class Context extends Component {

/*
var ValueManagerNode = React.createClass({
componentWillMount(){
this._setup({}, this.props)
},
componentWillReceiveProps(newProps, oldProps){
this._setup(oldProps, newProps);
},
_setup(old, newProps){
this._listener && this._listener.remove();
if (newProps.valueManager) {
this._listener = newProps.valueManager.addListener(null, this.update, this, true);
} else {
console.log('no valueManager');
}
},
update(value){
this.setState({value});
},
componentWillUnmount(){
this._listener && this._listener.remove();
},
render(){
return <div>
<h3>Values:</h3>
static childContextTypes = contextTypes
static contextTypes = contextTypes;
static propTypes = contextTypes;

getChildContext() {
var {loader, valueManager, schema} = this.props;
return {loader, valueManager, schema};
}

render() {
return <div>{this.props.children}</div>
}
}

class ValueManagerNode extends Component {
@listen("value", null)
update(value) {
this.setState({value});
}

render() {
return <div>
<h3>Values:</h3>
<pre className='value-manager-node'>
{JSON.stringify(this.state ? this.state.value : null, null, '\t')}
</pre>
</div>
}
</div>
}
}

class RenderPreview extends Component {
static contextTypes = contextTypes;

render() {
if (this.props.setupFunc) {
this.props.setupFunc(this.context.loader, this.context.schema, Subschema, React, this.context.valueManager);
}
provide.defaultLoader = this.context.loader;
var schema = cloneDeep(this.context.schema);

})
*/
return <Form schema={schema} valueManager={this.context.valueManager}
loader={this.context.loader}/>;
}
}

export default class Example extends Component {

Expand Down Expand Up @@ -81,54 +95,57 @@ export default class Example extends Component {
example
}
if (example.setupFile) {
config.setupTxt = require('!raw!!../samples/' + example.setupFile.replace(/\.\/?/, ''))
config.setupFunc = require('../sample-loader!../samples/' + example.setupFile.replace(/\.\/?/, ''))
config.setupTxt = require('!raw!!../samples/' + example.setupFile.replace(/^\.\/?/, ''))
config.setupFunc = require('../sample-loader!../samples/' + example.setupFile.replace(/^\.\/?/, ''))
} else {
config.setupTxt = '';
}


}

render() {
var value = {}, errors = null;
if (this.props.useData) {
value = this.config.example.data;
}
if (this.props.useError) {
errors = this.config.example.errors;
}
var loader = loaderFactory([DefaultLoader]);

var valueManager = ValueManager(value, errors);


return <div>
<h3>{this.props.example}</h3>
<p>{this.config.example.description}</p>
{this.renderPreview()}
<Highlight>
{`

<Context valueManager={valueManager} loader={loader} schema={cloneDeep(this.config.example.schema)}>
<RenderPreview/>
<ValueManagerNode/>
<Highlight>
{`
"use strict";
import React from 'react';
import Subschema from 'subschema';
var {loader, ValueManager } = Subschema;
var schema = ${JSON.stringify(this.config.example.schema, null, 2)}
${this.config.setupTxt}
`}
var schema = ${JSON.stringify(this.config.example.schema, null, 2)}
<Form schema={schema} loader={loader} valueManager={valueManager}/>
`}


</Highlight>
</Highlight>
</Context>
</div>
}

renderPreview() {
var value = {}, errors = null;
if (this.props.useData) {
value = this.config.example.data;
}
if (this.props.useError) {
errors = this.config.example.errors;
}
var loader = loaderFactory([DefaultLoader]);

var valueManager = ValueManager(value, errors);
var schema = cloneDeep(this.config.example.schema);
if (this.config.setupFunc) {
this.config.setupFunc(loader, schema, Subschema, React, valueManager);
}
provide.defaultLoader = loader;


return <Form schema={schema} valueManager={valueManager} loader={loader}/>;
return <RenderPreview setupFunc={this.config.setupFunc}/>
}

renderEdit() {
Expand Down
1 change: 0 additions & 1 deletion public/components/Link.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export default class Link extends Component {
}
handleClick = (e)=> {
e && e.preventDefault();
console.log('location', location);
this.props.onChange(!this.props.value);
}

Expand Down
21 changes: 0 additions & 21 deletions public/components/LinkTemplate.jsx

This file was deleted.

6 changes: 3 additions & 3 deletions public/components/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export default class Main extends Component {
if (/develop/.test(value)) {
var Develop = this.context.loader.loadTemplate(value);
if (Develop) {
return <Develop/>
return <Develop key={value}/>
}
} else if (value) {
return <Example example={value} useData={this.props.useData} useError={this.props.useError}/>
return <Example key={value} example={value} useData={this.props.useData} useError={this.props.useError}/>
}
return <Index/>
return <Index key={value}/>
}
}
14 changes: 0 additions & 14 deletions public/components/NavListTemplate.jsx

This file was deleted.

8 changes: 4 additions & 4 deletions public/components/Navigate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ export default class Navigate extends Component {
}
static defaultProps = {
pathname: "pathname",
href: '/{value}',
label: '{value}'
href: '/{.}',
label: '{.}'
}
clzName = (name)=> {
return 'list-group-item ' + ('/' + name.replace(/^#+?\//, '') === this.props.pathname ? 'active' : '');
Expand All @@ -25,7 +25,7 @@ export default class Navigate extends Component {
}

componentWillReceiveProps(props) {
if (!(props.href == this.props.href && props.label == this.props.label)) {
if (!(props.href === this.props.href && props.label === this.props.label)) {
this._setupFormatters(props);
}
}
Expand All @@ -38,7 +38,7 @@ export default class Navigate extends Component {

renderLink(value, i) {
var {...props} = this.props;
props.value = value;
props['.'] = value;
var href = this.hrefFormatter.format(props), label = this.labelFormatter.format(props);
return <a href={href} className={this.clzName(href)} key={'link-'+i}>{label}</a>
}
Expand Down
4 changes: 2 additions & 2 deletions public/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"samples": {
"type": "Navigate",
"template": false,
"href": "#/{value}"
"href": "#/{.}"
},
"develop": {
"type": "Navigate",
"template": false,
"href": "#/develop/{value}"
"href": "#/develop/{.}"
},
"pathname": {
"type": "Main",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Editor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default class Editor extends Component {
var field = props.field || FREEZE_OBJ;
var path = field.conditional && field.conditional.path || props.path;
var Node = context.loader.loadType(field.type);

warning(Node, 'subschema: did not find a type for %s', field.type);
var propTypes = Node.propTypes || FREEZE_OBJ,
overrideProps = {
className: forField(Node, field.className),
Expand Down

0 comments on commit 70ebd1f

Please sign in to comment.