Last active
October 11, 2017 22:53
-
-
Save itsdouges/21f9bc4b0284f00d05b50c3492e87d82 to your computer and use it in GitHub Desktop.
Potentially how to use gw2a react components with Angular
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
// store.js | |
import { combineReducers, applyMiddleware, createStore } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import { reducers, Tooltip } from 'armory-component-ui'; | |
const store = createStore( | |
// Create the root reducer. | |
combineReducers(reducers), | |
// Set the thunk middleware. | |
applyMiddleware(thunk), | |
); | |
export default store; | |
// react-provider-hoc.js | |
import React from 'react'; | |
import { Provider } from 'react-redux'; | |
import store from './store'; | |
const ProviderHOC = (Component) => (props) => React.createElement( | |
Provider, { | |
store, | |
children: React.createElement(Component, props, null), | |
}), null); | |
export default ProviderHOC; | |
// gw2item.js | |
import { Gw2Item } from 'armory-component-ui'; | |
import withStore from './react-provider-hoc'; | |
import ReactDOM from 'react-dom'; | |
const Gw2ItemWithStore = withStore(Gw2Item); | |
@Component({ inputs: ['id'] }) | |
export default class Gw2Item { | |
ngAfterViewInit () { | |
this.container = ReactDOM.render( | |
React.createElement(Gw2ItemWithStore, { id: this.id, /* Extra Props for It */ }), | |
this.el.nativeElement, | |
); | |
} | |
ngOnDestroy () { | |
ReactDOM.unmountComponentAtNode(this.container); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment