-
-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from plotly/try-to-add-async
Add an option to generate async component
- Loading branch information
Showing
14 changed files
with
295 additions
and
80 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
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
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
49 changes: 49 additions & 0 deletions
49
{{cookiecutter.project_shortname}}/cookiecutter_templates/AsyncComponent.react.js
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,49 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { {{cookiecutter.component_name}} as RealComponent } from '../LazyLoader'; | ||
|
||
/** | ||
* ExampleComponent is an example component. | ||
* It takes a property, `label`, and | ||
* displays it. | ||
* It renders an input with the property `value` | ||
* which is editable by the user. | ||
*/ | ||
export default class {{cookiecutter.component_name}} extends Component { | ||
render() { | ||
return ( | ||
<React.Suspense fallback={null}> | ||
<RealComponent {...this.props}/> | ||
</React.Suspense> | ||
); | ||
} | ||
} | ||
|
||
{{cookiecutter.component_name}}.defaultProps = {}; | ||
|
||
{{cookiecutter.component_name}}.propTypes = { | ||
/** | ||
* The ID used to identify this component in Dash callbacks. | ||
*/ | ||
id: PropTypes.string, | ||
|
||
/** | ||
* A label that will be printed when this component is rendered. | ||
*/ | ||
label: PropTypes.string.isRequired, | ||
|
||
/** | ||
* The value displayed in the input. | ||
*/ | ||
value: PropTypes.string, | ||
|
||
/** | ||
* Dash-assigned callback that should be called to report property changes | ||
* to Dash, to make them available for callbacks. | ||
*/ | ||
setProps: PropTypes.func | ||
}; | ||
|
||
|
||
export const defaultProps = {{cookiecutter.component_name}}.defaultProps; | ||
export const propTypes = {{cookiecutter.component_name}}.propTypes; |
61 changes: 61 additions & 0 deletions
61
{{cookiecutter.project_shortname}}/cookiecutter_templates/Component.react.js
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,61 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* ExampleComponent is an example component. | ||
* It takes a property, `label`, and | ||
* displays it. | ||
* It renders an input with the property `value` | ||
* which is editable by the user. | ||
*/ | ||
export default class {{cookiecutter.component_name}} extends Component { | ||
render() { | ||
const {id, label, setProps, value} = this.props; | ||
|
||
return ( | ||
<div id={id}> | ||
ExampleComponent: {label} | ||
<input | ||
value={value} | ||
onChange={ | ||
/* | ||
* Send the new value to the parent component. | ||
* setProps is a prop that is automatically supplied | ||
* by dash's front-end ("dash-renderer"). | ||
* In a Dash app, this will update the component's | ||
* props and send the data back to the Python Dash | ||
* app server if a callback uses the modified prop as | ||
* Input or State. | ||
*/ | ||
e => setProps({ value: e.target.value }) | ||
} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
{{cookiecutter.component_name}}.defaultProps = {}; | ||
|
||
{{cookiecutter.component_name}}.propTypes = { | ||
/** | ||
* The ID used to identify this component in Dash callbacks. | ||
*/ | ||
id: PropTypes.string, | ||
|
||
/** | ||
* A label that will be printed when this component is rendered. | ||
*/ | ||
label: PropTypes.string.isRequired, | ||
|
||
/** | ||
* The value displayed in the input. | ||
*/ | ||
value: PropTypes.string, | ||
|
||
/** | ||
* Dash-assigned callback that should be called to report property changes | ||
* to Dash, to make them available for callbacks. | ||
*/ | ||
setProps: PropTypes.func | ||
}; |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
66 changes: 5 additions & 61 deletions
66
...kiecutter.project_shortname}}/src/lib/components/{{cookiecutter.component_name}}.react.js
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,61 +1,5 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* ExampleComponent is an example component. | ||
* It takes a property, `label`, and | ||
* displays it. | ||
* It renders an input with the property `value` | ||
* which is editable by the user. | ||
*/ | ||
export default class {{cookiecutter.component_name}} extends Component { | ||
render() { | ||
const {id, label, setProps, value} = this.props; | ||
|
||
return ( | ||
<div id={id}> | ||
ExampleComponent: {label} | ||
<input | ||
value={value} | ||
onChange={ | ||
/* | ||
* Send the new value to the parent component. | ||
* setProps is a prop that is automatically supplied | ||
* by dash's front-end ("dash-renderer"). | ||
* In a Dash app, this will update the component's | ||
* props and send the data back to the Python Dash | ||
* app server if a callback uses the modified prop as | ||
* Input or State. | ||
*/ | ||
e => setProps({ value: e.target.value }) | ||
} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
{{cookiecutter.component_name}}.defaultProps = {}; | ||
|
||
{{cookiecutter.component_name}}.propTypes = { | ||
/** | ||
* The ID used to identify this component in Dash callbacks. | ||
*/ | ||
id: PropTypes.string, | ||
|
||
/** | ||
* A label that will be printed when this component is rendered. | ||
*/ | ||
label: PropTypes.string.isRequired, | ||
|
||
/** | ||
* The value displayed in the input. | ||
*/ | ||
value: PropTypes.string, | ||
|
||
/** | ||
* Dash-assigned callback that should be called to report property changes | ||
* to Dash, to make them available for callbacks. | ||
*/ | ||
setProps: PropTypes.func | ||
}; | ||
{%- if cookiecutter.use_async == "True" -%} | ||
{%- include 'cookiecutter_templates/AsyncComponent.react.js' -%} | ||
{%- else -%} | ||
{%- include 'cookiecutter_templates/Component.react.js' -%} | ||
{%- endif -%} |
41 changes: 41 additions & 0 deletions
41
...okiecutter.project_shortname}}/src/lib/fragments/{{cookiecutter.component_name}}.react.js
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,41 @@ | ||
import React, {Component} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {defaultProps, propTypes} from '../components/{{cookiecutter.component_name}}.react'; | ||
|
||
/** | ||
* ExampleComponent is an example component. | ||
* It takes a property, `label`, and | ||
* displays it. | ||
* It renders an input with the property `value` | ||
* which is editable by the user. | ||
*/ | ||
export default class {{cookiecutter.component_name}} extends Component { | ||
render() { | ||
const {id, label, setProps, value} = this.props; | ||
|
||
return ( | ||
<div id={id}> | ||
ExampleComponent: {label} | ||
<input | ||
value={value} | ||
onChange={ | ||
/* | ||
* Send the new value to the parent component. | ||
* setProps is a prop that is automatically supplied | ||
* by dash's front-end ("dash-renderer"). | ||
* In a Dash app, this will update the component's | ||
* props and send the data back to the Python Dash | ||
* app server if a callback uses the modified prop as | ||
* Input or State. | ||
*/ | ||
e => setProps({ value: e.target.value }) | ||
} | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
|
||
{{cookiecutter.component_name}}.defaultProps = defaultProps; | ||
{{cookiecutter.component_name}}.propTypes = propTypes; |
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
Oops, something went wrong.