mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
add <Config> higher order component heavily inspired by @nfcampos (#59)
This commit is contained in:
parent
95d2392f35
commit
318f684da4
2 changed files with 38 additions and 1 deletions
36
app/config.js
Normal file
36
app/config.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import React from 'react';
|
||||
import { ipcRenderer, remote } from 'electron';
|
||||
|
||||
const config = remote.require('./config');
|
||||
|
||||
export default class Config extends React.Component {
|
||||
|
||||
constructor () {
|
||||
super();
|
||||
this.state = {
|
||||
config: config.get()
|
||||
};
|
||||
this.onChange = this.onChange.bind(this);
|
||||
}
|
||||
|
||||
onChange () {
|
||||
new Notification('HyperTerm configuration reloaded!');
|
||||
this.setState({ config: config.get() });
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
ipcRenderer.on('config change', this.onChange);
|
||||
}
|
||||
|
||||
// passes `config` as props to the decorated component
|
||||
render () {
|
||||
const child = React.Children.only(this.props.children);
|
||||
const { config } = this.state;
|
||||
return React.cloneElement(child, { config });
|
||||
}
|
||||
|
||||
componentWillUnmount () {
|
||||
ipcRenderer.removeListener('config change', this.onChange);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,9 @@
|
|||
import { render } from 'react-dom';
|
||||
import HyperTerm from './hyperterm';
|
||||
import React from 'react';
|
||||
import Config from './config';
|
||||
|
||||
require('./css/hyperterm.css');
|
||||
require('./css/tabs.css');
|
||||
|
||||
render(<HyperTerm />, document.getElementById('mount'));
|
||||
render(<Config><HyperTerm /></Config>, document.getElementById('mount'));
|
||||
|
|
|
|||
Loading…
Reference in a new issue