Skip to content

make env configurable #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ The asynchronous component factory. Config goes in, an asynchronous component co
- `ErrorComponent` (_Component_, Optional, default: `null`) : A Component that will be displayed if any error occurred whilst trying to resolve your component. All props will be passed to it as well as an `error` prop containing the `Error`.
- `name` (_String_, Optional, default: `'AsyncComponent'`) : Use this if you would like to name the created async Component, which helps when firing up the React Dev Tools for example.
- `autoResolveES2015Default` (_Boolean_, Optional, default: `true`) : Especially useful if you are resolving ES2015 modules. The resolved module will be checked to see if it has a `.default` and if so then the value attached to `.default` will be used. So easy to forget to do that. 😀
- `env` (_String_, Optional) : Provide either `'node'` or `'browser'` so you can write your own environment detection. Especially useful when using PhantomJS or ElectronJS to prerender the React App.
- `serverMode` (_Boolean_, Optional, default: `'resolve'`) : Only applies for server side rendering applications. Please see the documentation on server side rendering. The following values are allowed.
- __`'resolve'`__ - Your asynchronous component will be resolved and rendered on the server. It's children will
be checked to see if there are any nested asynchronous component instances, which will then be processed based on the `serverMode` value that was associated with them.
Expand Down
2 changes: 1 addition & 1 deletion commonjs/asyncComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function asyncComponent(config) {
throw new Error('Invalid serverMode provided to asyncComponent');
}

var env = typeof window === 'undefined' ? 'node' : 'browser';
var env = ['node', 'browser'].indexOf(config.env) > -1 ? config.env : typeof window === 'undefined' ? 'node' : 'browser';

var sharedState = {
// A unique id we will assign to our async component which is especially
Expand Down
4 changes: 3 additions & 1 deletion src/asyncComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ function asyncComponent(config) {
throw new Error('Invalid serverMode provided to asyncComponent')
}

const env = typeof window === 'undefined' ? 'node' : 'browser'
const env = ['node', 'browser'].indexOf(config.env) > -1
? config.env
: typeof window === 'undefined' ? 'node' : 'browser'

const sharedState = {
// A unique id we will assign to our async component which is especially
Expand Down
2 changes: 1 addition & 1 deletion umd/react-async-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function asyncComponent(config) {
throw new Error('Invalid serverMode provided to asyncComponent');
}

var env = typeof window === 'undefined' ? 'node' : 'browser';
var env = ['node', 'browser'].indexOf(config.env) > -1 ? config.env : typeof window === 'undefined' ? 'node' : 'browser';

var sharedState = {
// A unique id we will assign to our async component which is especially
Expand Down
2 changes: 1 addition & 1 deletion umd/react-async-component.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.