toolness / p5.js-widget

A reusable widget for embedding editable p5 sketches in web pages.
https://toolness.github.io/p5.js-widget/
GNU Lesser General Public License v2.1
162 stars 44 forks source link

Add a basic console #7

Open toolness opened 8 years ago

toolness commented 8 years ago

As @indefinit metioned in https://github.com/processing/p5.js-website/issues/198#issuecomment-207504978, it'd be nice to have some kind of console in the widget. Right now we show the last error that occurred in the "status bar" at the bottom of the widget, but that's it.

We talked a bit about web consoles in a recent p5 working group meeting, and noted a few things about the various web-based tools out there that have consoles:

toolness commented 8 years ago

Er, on the other hand, I should also note that the conversation we had at the p5 working group was about the console for the web-based IDE, which is actually quite a different use case for this snippet editor. The consoles of most web-based tools do work okay for very simple programs, and it's likely this widget will only really be used for tiny sketches, so we can probably get away with providing something fairly simple that doesn't scale.

indefinit commented 8 years ago

Ah ok this all makes sense. I tried messing around with my fork of your widget but I'm not sure if I'm good enough at React/Typescript to understand how one would even evaluate console log messages. One very hacky workaround I could think of would be to redefine the println function so that instead of aliasing console.log it just passes the value along to the innerHTML of a dom element, however I don't think that's a very futureproof solution.

toolness commented 8 years ago

I tried messing around with my fork of your widget but I'm not sure if I'm good enough at React/Typescript to understand how one would even evaluate console log messages

Oy, sorry about that. :disappointed: I should have considered the higher barrier to entry using React and TypeScript would incur before starting this project... At the same time, they are making development a lot less painful for me, so maybe I could write a mini-guide on getting up-to-speed with these technologies. Would that be helpful?

shiffman commented 8 years ago

I'd certainly be curious for that guide!

toolness commented 8 years ago

@shiffman I took a stab at the beginning of a tutorial here, would love your thoughts!

https://github.com/toolness/p5.js-widget/wiki/A-React-Tutorial-for-p5-Programmers

shiffman commented 8 years ago

This is great! One thing I might be curious for is some context. What role does react play in p5.js-widget and why did you choose to use react?

The other piece of advice I have (and I'm not 100% sure about this) is that for beginners it's sometimes helpful to see elegantly written compressed code broken out in more long-winded ways, i.e. instead of something like:

var Sketch = React.createClass({ . . . . . . });

You could write:

var component = { . . . . . . };  // What should this variable be called?
var Sketch = React.createClass(component);

And then perhaps condense it in a later state.

The reason I'm not sure about this is b/c these longer-winded ways of writing things don't seem to be typical JS style (and I'm not a JS native), but I find that when teaching starting without anonymous functions (for example) and then moving into them often helps students understand the pieces of a program.

toolness commented 8 years ago

Awesome, thanks for the advice!!

I added a section here providing some context, does it help?

https://github.com/toolness/p5.js-widget/wiki/A-React-Tutorial-for-p5-Programmers#why-react

toolness commented 8 years ago

Just added a What is React? section too!