Skip to content

Commit

Permalink
Show preview console lines in console view
Browse files Browse the repository at this point in the history
See #5
  • Loading branch information
priithaamer committed Nov 19, 2016
1 parent 0198037 commit 8192734
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ const jsEditor = CodeMirror(document.querySelector('.js-editor'), Object.assign(
mode: 'javascript',
}));
jsEditor.on('change', (editor, change) => {
updateContents('javascript', editor.doc.getValue());
try {
const value = editor.doc.getValue();
const result = eval.call(null, value);
updateContents('javascript', value);
} catch (e) {
console.log('Error in javascript', e);
}
});

const preview = document.querySelector('#preview');
Expand All @@ -99,10 +105,6 @@ const updateContents = (kind, contents) => {
preview.send('updater', kind, contents);
};

preview.addEventListener('console-message', (e) => {
console.log('Preview pane log:', e.message);
});

preview.addEventListener('dom-ready', () => {
updateContents('html', htmlEditor.doc.getValue());
updateContents('css', cssEditor.doc.getValue());
Expand All @@ -111,23 +113,30 @@ preview.addEventListener('dom-ready', () => {

const consoleInput = document.querySelector('.console-input');
const consoleLines = document.querySelector('.console-lines');

function addConsoleLine(content) {
var line = document.createElement('div');
line.innerHTML = content;
consoleLines.appendChild(line);
}

consoleInput.addEventListener('keyup', (event) => {
if (event.key === 'Enter') {
const inputValue = event.target.value;

preview.executeJavaScript(inputValue, false, (result) => {
var line1 = document.createElement('div');
line1.innerHTML = inputValue;
consoleLines.appendChild(line1);
var line = document.createElement('div');
line.innerHTML = JSON.stringify(result);
consoleLines.appendChild(line);
addConsoleLine(inputValue);
addConsoleLine(JSON.stringify(result));
});
event.target.value = '';
event.target.focus();
}
});

preview.addEventListener('console-message', (e) => {
addConsoleLine(e.message);
});

const {remote} = electron;
const {Menu} = remote;

Expand Down

0 comments on commit 8192734

Please sign in to comment.