forked from ManageIQ/manageiq-ui-classic
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated to react 16. * created a component mounting helper to initalize react componenets from rails views * create a component registery, so that plugins can register their top level containers * broke down generate webpack chunks into plugin specific vs common js code (to avoid duplications of js code within the bundle) * change webpack source maps to inline so it can easily be used to debug in the browser. (see webpack/webpack#2145) * updated webpack configuration so it can read from a package.json defined on a plugin
- Loading branch information
Showing
10 changed files
with
106 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
{ | ||
"root": true, | ||
"installedESLint": true, | ||
"env": { | ||
"browser": true, | ||
"jquery": true | ||
|
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,7 @@ | ||
module ReactjsHelper | ||
def mount_react_component(name, selector, data = []) | ||
javascript_tag(:defer => 'defer') do | ||
"$(MiqReact.mount('#{name}', '#{selector}', #{data.to_json}));".html_safe | ||
end | ||
end | ||
end |
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,59 @@ | ||
import React from 'react'; | ||
import forEach from 'lodash/forEach'; | ||
import map from 'lodash/map'; | ||
|
||
const componentRegistry = { | ||
registry: {}, | ||
|
||
register({ name = null, type = null, store = true, data = true }) { | ||
if (!name || !type) { | ||
throw new Error('Component name or type is missing'); | ||
} | ||
if (this.registry[name]) { | ||
throw new Error(`Component name already taken: ${name}`); | ||
} | ||
|
||
this.registry[name] = { type, store, data }; | ||
return this.registry; | ||
}, | ||
|
||
registerMultiple(componentObjs) { | ||
return forEach(componentObjs, obj => { | ||
return this.register(obj); | ||
}); | ||
}, | ||
|
||
getComponent(name) { | ||
return this.registry[name]; | ||
}, | ||
|
||
registeredComponents() { | ||
return map(this.registry, (value, key) => { | ||
return key; | ||
}).join(', '); | ||
}, | ||
|
||
markup(name, data, store) { | ||
const currentComponent = this.getComponent(name); | ||
|
||
if (!currentComponent) { | ||
throw new Error( | ||
`Component not found: ${name} among ${this.registeredComponents()}` | ||
); | ||
} | ||
const ComponentName = currentComponent.type; | ||
|
||
return ( | ||
<ComponentName | ||
data={currentComponent.data ? data : undefined} | ||
store={currentComponent.store ? store : undefined} | ||
/> | ||
); | ||
} | ||
}; | ||
|
||
const coreComponets = []; | ||
|
||
componentRegistry.registerMultiple(coreComponets); | ||
|
||
export default componentRegistry; |
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,17 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import componentRegistry from './componentRegistry'; | ||
|
||
export function mount(component, selector, data = {}) { | ||
const reactNode = document.querySelector(selector); | ||
|
||
if (reactNode) { | ||
ReactDOM.unmountComponentAtNode(reactNode); | ||
ReactDOM.render(componentRegistry.markup(component, data), reactNode); | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.log( | ||
`Cannot find \'${selector}\' element for mounting the \'${component}\'` | ||
); | ||
} | ||
} |
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