Skip to content

Commit

Permalink
Merge pull request #339 from CPatchane/react_as_aliases
Browse files Browse the repository at this point in the history
Handled global React as aliases instead
  • Loading branch information
ptbrowne authored Nov 12, 2018
2 parents 3f6ef8b + 7e97103 commit 73f7410
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 49 deletions.
1 change: 1 addition & 0 deletions config/aliases/globalReact.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = window.React || require('react-bundled')
1 change: 1 addition & 0 deletions config/aliases/globalReactDOM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = window.ReactDOM || require('react-dom-bundled')
14 changes: 8 additions & 6 deletions config/webpack.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ const pkg = require('../package.json')
const SRC_DIR = path.resolve(__dirname, '../src')

module.exports = {
entry: [
// Check for global React or load dependency
path.resolve(__dirname, '../src/prepareReact.js'),
path.resolve(__dirname, '../src/index')
],
entry: path.resolve(__dirname, '../src/index'),
output: {
library: ['cozy', 'bar'],
libraryTarget: 'umd',
umdNamedDefine: true
},
resolve: {
extensions: ['.js', '.json', '.yaml'],
modules: [SRC_DIR, path.join(__dirname, '../node_modules')]
modules: [SRC_DIR, path.join(__dirname, '../node_modules')],
alias: {
react: path.resolve(__dirname, 'aliases/globalReact'),
'react-dom': path.resolve(__dirname, 'aliases/globalReactDOM'),
'react-bundled': 'react',
'react-dom-bundled': 'react-dom'
}
},
devtool: '#source-map',
module: {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@
"yaml"
],
"setupFiles": [
"<rootDir>/test/jestLib/setup.js",
"<rootDir>/src/prepareReact.js"
"<rootDir>/test/jestLib/setup.js"
],
"moduleDirectories": [
"node_modules",
Expand Down
3 changes: 2 additions & 1 deletion src/components/Apps/AppItem.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global __TARGET__, React */
/* global __TARGET__ */

import React from 'react'
import { appShape } from 'proptypes/index'
import { checkApp, startApp } from 'cozy-device-helper'
import expiringMemoize from 'lib/expiringMemoize'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Apps/AppItemPlaceholder.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global React */
import React from 'react'

export const AppItemPlaceholder = () => (
<li className="coz-nav-apps-item">
Expand Down
4 changes: 2 additions & 2 deletions src/components/Apps/AppNavButtons.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global React */
import React, { Component } from 'react'
import { connect } from 'react-redux'

import { getHomeApp } from 'lib/reducers'
Expand All @@ -8,7 +8,7 @@ import Icon from 'cozy-ui/react/Icon'
import homeIcon from 'assets/icons/icon-cozy-home.svg'
import { isFetchingApps } from 'lib/reducers'

class AppNavButton extends React.Component {
class AppNavButton extends Component {
render() {
const {
homeApp,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Apps/AppsContent.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global React */
import React, { Component } from 'react'
import { connect } from 'react-redux'

import { translate } from 'cozy-ui/react/I18n'
Expand All @@ -10,7 +10,7 @@ import AppItemPlaceholder from 'components/Apps/AppItemPlaceholder'
import cozyIcon from 'assets/icons/16/icon-cozy-16.svg'
import homeIcon from 'assets/icons/icon-cozy-home.svg'

class AppsContent extends React.Component {
class AppsContent extends Component {
constructor(props, context) {
super(props, context)
this.translateApp = translateApp(this.props.t)
Expand Down
4 changes: 2 additions & 2 deletions src/components/Apps/index.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global React */
import React, { Component } from 'react'

import AppsContent from 'components/Apps/AppsContent'
import AppNavButtons from 'components/Apps/AppNavButtons'

class Apps extends React.Component {
class Apps extends Component {
constructor(props) {
super(props)
this.state = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Banner.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global React */
import React, { Component } from 'react'
import { ButtonLink } from 'cozy-ui/react/Button'
import { translate } from 'cozy-ui/react/I18n'

class Banner extends React.Component {
class Banner extends Component {
constructor(props) {
super(props)
this.state = { unmounted: true }
Expand Down
5 changes: 3 additions & 2 deletions src/components/Bar.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global __PIWIK_TRACKER_URL__ __PIWIK_SITEID__ __PIWIK_DIMENSION_ID_APP__, React */
/* global __PIWIK_TRACKER_URL__ __PIWIK_SITEID__ __PIWIK_DIMENSION_ID_APP__ */

import 'core-js/modules/es6.object.assign'
import React, { Component } from 'react'
import { connect } from 'react-redux'

import { translate } from 'cozy-ui/react/I18n'
Expand All @@ -26,7 +27,7 @@ import {
shouldEnableClaudy
} from 'lib/reducers'

class Bar extends React.Component {
class Bar extends Component {
constructor(props) {
super(props)
this.state = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Claudy.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global React */
import React, { Component } from 'react'
import { create as createIntent } from 'lib/intents'

class Claudy extends React.Component {
class Claudy extends Component {
constructor(props, context) {
super(props)
this.store = context.barStore
Expand Down
4 changes: 2 additions & 2 deletions src/components/Drawer.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global React */
import React, { Component } from 'react'
import { connect } from 'react-redux'
import Hammer from 'hammerjs'

Expand All @@ -11,7 +11,7 @@ import {
logOut
} from 'lib/reducers'

class Drawer extends React.Component {
class Drawer extends Component {
constructor(props) {
super(props)
this.state = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/SearchBar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global React */
import React, { Component } from 'react'
import { translate } from 'cozy-ui/react/I18n'
import Autosuggest from 'react-autosuggest'
import debounce from 'lodash.debounce'
Expand Down Expand Up @@ -91,7 +91,7 @@ const highlightQueryTerms = (searchResult, query) => {
return slicedOriginalResult
}

class SearchBar extends React.Component {
class SearchBar extends Component {
state = {
input: '',
query: null,
Expand Down
3 changes: 2 additions & 1 deletion src/components/Settings/SettingsContent.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global __TARGET__, React */
/* global __TARGET__ */
import React from 'react'

import { translate } from 'cozy-ui/react/I18n'

Expand Down
2 changes: 1 addition & 1 deletion src/components/Settings/StorageData.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global React */
import React from 'react'
import { translate } from 'cozy-ui/react/I18n'

const StorageData = ({ t, data }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Settings/index.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global React */
import React, { Component } from 'react'
import { connect } from 'react-redux'

import { translate } from 'cozy-ui/react/I18n'
Expand All @@ -13,7 +13,7 @@ import {
logOut
} from 'lib/reducers'

class Settings extends React.Component {
class Settings extends Component {
constructor(props) {
super(props)
this.state = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/SupportModal.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global React */
import React, { Component } from 'react'
import Modal, { ModalContent } from 'cozy-ui/react/Modal'
import Spinner from 'cozy-ui/react/Spinner'
import { create as createIntent } from 'lib/intents'

class SupportModal extends React.Component {
class SupportModal extends Component {
constructor(props, context) {
super(props)
this.store = context.barStore
Expand Down
7 changes: 4 additions & 3 deletions src/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/* global __TARGET__, __VERSION__, React, ReactDOM */
/* global __TARGET__, __VERSION__ */

'use strict'

import React from 'react'
import { render } from 'react-dom'

import I18n from 'cozy-ui/react/I18n'
import stack from './lib/stack'
import {
Expand All @@ -21,8 +24,6 @@ import api from 'lib/api'
require('./styles')
require('./lib/importIcons')

const { render } = ReactDOM

const APP_SELECTOR = '[role=application]'

// store
Expand Down
5 changes: 2 additions & 3 deletions src/lib/api.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global React */

import React, { Component } from 'react'
import { getContent, setContent, setLocale } from './reducers'

const upperFirstLetter = val => {
Expand Down Expand Up @@ -28,7 +27,7 @@ const wrapInElement = v => {
* @param {BarStore} store
*/
const barContentComponent = (store, location) =>
class BarContent extends React.Component {
class BarContent extends Component {
componentDidMount() {
this.prev = getContent(store.getState(), location)
this.setContent(this.props.children)
Expand Down
11 changes: 0 additions & 11 deletions src/prepareReact.js

This file was deleted.

0 comments on commit 73f7410

Please sign in to comment.