Skip to content

Commit

Permalink
Moved to subschema core
Browse files Browse the repository at this point in the history
  • Loading branch information
juspears committed Feb 24, 2016
1 parent 3c5722a commit 8341c76
Show file tree
Hide file tree
Showing 41 changed files with 48 additions and 1,631 deletions.
56 changes: 0 additions & 56 deletions gh-pages.sh

This file was deleted.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
"description": "Subschema Injection System.",
"main": "",
"dependencies": {},
"repository": "",
"repository": {
"type": "git",
"url": "https://github.com/subschema/subschema-injection"
},
"publishConfig": {
"registry": ""
"registry": "https://registry.npmjs.org"
},
"author": "",
"license": "",
Expand Down Expand Up @@ -40,8 +43,6 @@
"react-transform-catch-errors": "^1.0.1",
"react-transform-hmr": "^1.0.1",
"style-loader": "^0.13.0",
"subschema": "^0.54.0",
"subschema-test-support": "^1.0.4",
"url-loader": "^0.5.7",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.0"
Expand Down
22 changes: 0 additions & 22 deletions src/Field.jsx

This file was deleted.

16 changes: 6 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
"use strict";

import {PropTypes as ReactPropTypes} from 'react';
import injector from './injector';
import resolvers from './resolvers';
import {PropTypes} from 'subschema';

Object.keys(resolvers).map(function (k) {
if (PropTypes[k] && resolvers[k]) {
injector.resolver(PropTypes[k], resolvers[k])
} else {
// console.log('missing ', k, PropTypes[k], resolvers[k]);
}
});
export const PropTypes = {
injector: ReactPropTypes.shape({
inject: ReactPropTypes.func.isRequired
})
};

export default injector;
39 changes: 26 additions & 13 deletions src/injectorFactory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
import React, {Component} from 'react';
import {keyIn,onlyKeys, uniqueKeys} from './util';
import {keyIn, onlyKeys, uniqueKeys} from './util';

export class BaseInjectComponent extends Component {
state = {};
Expand Down Expand Up @@ -31,18 +31,15 @@ export default function injector(resolvers = []) {
resolve
});
},


inject(Clazz, extraPropTypes, extraProps, strictProps){
const {defaultProps, propTypes} = Clazz;
const propTypeKeys = uniqueKeys(propTypes, extraPropTypes, defaultProps);
const [...copyPropTypeKeys] = propTypeKeys;
createWrapperClass(Clazz, copyPropTypeKeys, strictProps){
const render = strictProps !== false ? function render() {
const {children, ...rest} = this.props;
const props = onlyKeys(copyPropTypeKeys, this.injected, this.props);
return <Clazz {...props} >{this.props.children}</Clazz>

} : function loosePropsRender() {
return <Clazz {...this.props} {...this.injected }>{this.props.children}</Clazz>
const {children, ...props} = this.props;
return children ? <Clazz {...props} {...this.injected }>{children}</Clazz> : <Clazz {...props} {...this.injected }/>

};
//BaseInjectComponent is just a marker class.
Expand All @@ -51,15 +48,31 @@ export default function injector(resolvers = []) {
static contextTypes = {};
render = render;
}
if ('template' in Clazz){
InjectedClass.template = Clazz.template;
}
return InjectedClass
},
/**
* Injects properties based propType.
*
* @param Clazz - class to wrap.
* @param extraPropTypes - extra prop types if the component does not have the propType than it will use this propType, otherwise the
* the class'es default propType will be used.
* @param extraProps - If a component has a defaultProp than it will use that otherwise it will use this.
* @param strictProps - If false than it will pass all props on to component, otherwise it just passes defined props.
* @returns {*}
*/

inject(Clazz, extraPropTypes, extraProps, strictProps){
const {defaultProps, propTypes} = Clazz;
const propTypeKeys = uniqueKeys(propTypes, defaultProps, extraPropTypes);
const [...copyPropTypeKeys] = propTypeKeys;

const InjectedClass = this.createWrapperClass(Clazz, copyPropTypeKeys, strictProps);

return propTypeKeys.reduce((injectedClass, key)=> {

const propType = keyIn(key, extraPropTypes, propTypes);
const propType = keyIn(key, propTypes, extraPropTypes);

injectedClass.defaultProps[key] = keyIn(key, extraProps, defaultProps);
injectedClass.defaultProps[key] = keyIn(key, defaultProps, extraProps);

const nextClass = resolveProp(injectedClass, propType, key, copyPropTypeKeys, Clazz);

Expand Down
6 changes: 0 additions & 6 deletions src/resolvers.js

This file was deleted.

50 changes: 0 additions & 50 deletions src/resolvers/blurValidate.js

This file was deleted.

39 changes: 0 additions & 39 deletions src/resolvers/conditional.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/resolvers/content.js

This file was deleted.

31 changes: 0 additions & 31 deletions src/resolvers/dataType.js

This file was deleted.

21 changes: 0 additions & 21 deletions src/resolvers/error.js

This file was deleted.

16 changes: 0 additions & 16 deletions src/resolvers/errorEvent.js

This file was deleted.

Loading

0 comments on commit 8341c76

Please sign in to comment.