mirror of
https://github.com/morten-olsen/react-native-debug-console.git
synced 2026-02-08 00:36:26 +01:00
init
This commit is contained in:
43
lib/src/components/data/Log.js
Normal file
43
lib/src/components/data/Log.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Component } from 'react';
|
||||
import log from '../../log';
|
||||
|
||||
class Log extends Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
logs: [],
|
||||
};
|
||||
this.addLog = this.addLog.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
log.listen(this.addLog);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
log.unlisten(this.addLog);
|
||||
}
|
||||
|
||||
addLog(entry) {
|
||||
entry = Array.isArray(entry) ? entry : [entry];
|
||||
const logs = [
|
||||
...this.state.logs,
|
||||
...entry,
|
||||
];
|
||||
this.setState({
|
||||
logs,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
children,
|
||||
} = this.props;
|
||||
const component = children(
|
||||
this.state,
|
||||
);
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
export default Log;
|
||||
43
lib/src/components/data/Network.js
Normal file
43
lib/src/components/data/Network.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import { Component } from 'react';
|
||||
import network from '../../network';
|
||||
|
||||
class Network extends Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
requests: [],
|
||||
};
|
||||
this.addRequest = this.addRequest.bind(this);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
network.listen(this.addRequest);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
network.unlisten(this.addRequest);
|
||||
}
|
||||
|
||||
addRequest(request) {
|
||||
request = Array.isArray(request) ? request : [request];
|
||||
const requests = [
|
||||
...this.state.requests,
|
||||
...request,
|
||||
];
|
||||
this.setState({
|
||||
requests,
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
const {
|
||||
children,
|
||||
} = this.props;
|
||||
const component = children(
|
||||
this.state,
|
||||
);
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
export default Network;
|
||||
20
lib/src/components/data/State.js
Normal file
20
lib/src/components/data/State.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import React, { Component } from 'react';
|
||||
|
||||
class State extends Component {
|
||||
constructor(props, ...others) {
|
||||
super(props, ...others);
|
||||
this.state = props.initState || {};
|
||||
this.setState = this.setState.bind(this);
|
||||
}
|
||||
|
||||
render() {
|
||||
const { children } = this.props;
|
||||
const component = children(
|
||||
this.state,
|
||||
this.setState,
|
||||
);
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
export default State;
|
||||
Reference in New Issue
Block a user