-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): refactor react-indie api (#7)
Currently the indie function returns a react rendered markup. it should be wrapped in a function so it can return a component instead. BREAKING CHANGE: indie to render component. closes #6
- Loading branch information
Showing
9 changed files
with
98 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
export const SimpleComponent = (props) => { | ||
const styles = { | ||
wrapper: { | ||
padding: 10, | ||
fontFamily: 'helvetica', | ||
backgroundColor: props.bgColor, | ||
color: '#fff', | ||
maxWidth: 400, | ||
borderRadius: 5, | ||
margin: 5, | ||
}, | ||
}; | ||
return ( | ||
<div style={styles.wrapper}> | ||
<h1>{ props.title }</h1> | ||
<p>{ props.subtitle }</p> | ||
</div> | ||
); | ||
}; | ||
|
||
SimpleComponent.propTypes = { | ||
bgColor: PropTypes.string, | ||
subtitle: PropTypes.string, | ||
title: PropTypes.string, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,34 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import MyWidget from './components/my-widget/index'; | ||
import indie from '../src/index.js'; | ||
import { SimpleComponent } from './SimpleComponent.js'; | ||
|
||
// helpers | ||
|
||
function mockAjaxRequest() { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve('Loaded title'); | ||
}, 1000); | ||
}); | ||
} | ||
|
||
// Widget1 | ||
// * Widget get default data | ||
// * Widgets load data from the server | ||
|
||
const widget1propsConfig = { | ||
title: ['Loading...', mockAjaxRequest()], | ||
subtitle: ['Please wait', 'Loaded subtitle'], | ||
bgColor: ['#ccc', '#1bc98e'], | ||
}; | ||
|
||
const Widget1 = indie(SimpleComponent, widget1propsConfig); | ||
|
||
ReactDOM.render( | ||
<div><MyWidget /></div>, | ||
(<div> | ||
<h1>Example Page</h1> | ||
<Widget1 /> | ||
</div>), | ||
document.getElementById('app') | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { Component } from 'react'; | ||
import { props as promiseProps } from 'bluebird'; | ||
import { forEach } from 'lodash'; | ||
|
||
export default (ReactComponent, propsConfig) => class extends Component { | ||
constructor(props) { | ||
super(props); | ||
[this.defaultProps, this.loadedProps] = [{}, {}]; | ||
forEach(propsConfig, ([defaultProp, loadedProp, errorProp], key) => { | ||
this.defaultProps[key] = defaultProp; | ||
this.loadedProps[key] = loadedProp || defaultProp; | ||
}); | ||
this.state = this.defaultProps; | ||
promiseProps(this.loadedProps) | ||
.then(res => { | ||
this.setState(res); | ||
}); | ||
} | ||
render() { | ||
return (<ReactComponent {...this.state} />); | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters