diff --git a/demo/App.js b/demo/App.js
index 890fe0f..47a2272 100644
--- a/demo/App.js
+++ b/demo/App.js
@@ -1,7 +1,6 @@
import React from 'react';
import {
StyleSheet,
- Text,
View,
Button,
KeyboardAvoidingView,
@@ -17,7 +16,7 @@ import {
} from 'react-native-debug-console';
network.attach();
-log.attach();
+log.attach(true);
console.log('fooo');
let xhr = new XMLHttpRequest();
@@ -117,8 +116,13 @@ export default class App extends React.Component {
style={{
flex: 1,
}}
+ storageProvider={AsyncStorage}
+ context={global}
+ />
+
-
);
diff --git a/lib/src/components/DevTool/Console/Input.js b/lib/src/components/DevTool/Console/Input.js
index ecb9862..0d7a072 100644
--- a/lib/src/components/DevTool/Console/Input.js
+++ b/lib/src/components/DevTool/Console/Input.js
@@ -3,6 +3,7 @@ import {
StyleSheet,
View,
TextInput,
+ Platform,
} from 'react-native';
import styled from 'styled-components/native';
import { createContext } from '../../../console';
@@ -33,11 +34,29 @@ const styles = StyleSheet.create({
const Input = ({
provider,
- logs,
+ context: baseContext,
}) => {
const [text, setText] = useState('');
const [history, setHistory] = useState([]);
const [historyOffset, setHistoryOffset] = useState();
+
+ const send = () => {
+ const newHistory = [...history, text];
+ const context = createContext({
+ logProvider: provider,
+ }, baseContext);
+ const contextKeys = Object.keys(context);
+ const contextValues = Object.values(context);
+ const fn = new Function(...contextKeys, text);
+ try {
+ fn(...contextValues);
+ setText('');
+ setHistoryOffset(undefined);
+ setHistory(newHistory);
+ } catch (err) {
+ provider.error([err]);
+ }
+ };
return (
);
};
diff --git a/lib/src/components/DevTool/Modal.js b/lib/src/components/DevTool/Modal.js
index 7dd463f..ea993ff 100644
--- a/lib/src/components/DevTool/Modal.js
+++ b/lib/src/components/DevTool/Modal.js
@@ -53,7 +53,7 @@ class Events extends Component {
}}
>
{
@@ -36,6 +37,7 @@ const DevTool = ({
),
getData: log.get,
diff --git a/lib/src/console.js b/lib/src/console.js
index d40565b..1dea6e0 100644
--- a/lib/src/console.js
+++ b/lib/src/console.js
@@ -1,6 +1,9 @@
export const createContext = ({
logProvider,
-}) => ({
+}, baseContext = {}) => ({
log: (...args) => logProvider.log(...args),
clear: logProvider.clear,
+ window: baseContext,
+ global: baseContext,
+ context: baseContext,
});
\ No newline at end of file
diff --git a/lib/src/log.js b/lib/src/log.js
index 545e5a0..b4db42c 100644
--- a/lib/src/log.js
+++ b/lib/src/log.js
@@ -60,11 +60,12 @@ class Log {
handleError(err) {
if (err && err.error) {
- this.error([err.error], true);
+ this.error([err.error]);
}
}
attach(keep) {
+ global.proxyConsole = proxyConsole;
const redirected = Object.keys(proxyConsole).reduce((output, key) => ({
...output,
[key]: keep ? (...args) => proxyConsole[key](...args) : () => {},