Skip to content

Commit

Permalink
Simplify context pass
Browse files Browse the repository at this point in the history
  • Loading branch information
vovkasm committed Dec 16, 2016
1 parent f085db4 commit 21112b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/Provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ export default class Provider extends React.Component {
children: PropTypes.element.isRequired
}
static childContextTypes = {
styleSheet: PropTypes.object.isRequired,
styleSheetContext: PropTypes.string.isRequired
styleSheet: PropTypes.object.isRequired
}

constructor (props, ctx) {
super(props, ctx)
this.styleSheet = props.styleSheet
}
getChildContext () {
return {styleSheetContext: '', styleSheet: this.styleSheet}
return {styleSheet: this.styleSheet}
}
render () {
return Children.only(this.props.children)
Expand Down
16 changes: 6 additions & 10 deletions src/stylable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,30 @@ export default function stylable (name) {
static WrappedComponent = WrappedComponent
static contextTypes = {
styleSheet: PropTypes.object.isRequired,
styleSheetContext: PropTypes.string.isRequired
styleSheetContext: PropTypes.string
}
static childContextTypes = {
styleSheet: PropTypes.object.isRequired,
styleSheetContext: PropTypes.string.isRequired
}

constructor (props, ctx) {
super(props, ctx)
this.styleSheet = ctx.styleSheet
let path = ctx.styleSheetContext
if (path.length === 0) {
path = name
if (ctx.styleSheetContext === undefined) {
this.path = name
} else {
path += ' ' + name
this.path = ctx.styleSheetContext + ' ' + name
}
this.styleSheetContext = path
}

getChildContext () {
return {
styleSheet: this.styleSheet,
styleSheetContext: this.styleSheetContext
styleSheetContext: this.path
}
}

render () {
const props = this.styleSheet.getProps(this.styleSheetContext, this.props)
const props = this.styleSheet.getProps(this.path, this.props)
return React.createElement(WrappedComponent, props)
}
}
Expand Down

0 comments on commit 21112b5

Please sign in to comment.