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
161 stars 44 forks source link

Add foundational support for loading p5 addons in preview-frame.ts. #63

Closed toolness closed 8 years ago

toolness commented 8 years ago

This adds foundational support for loading multiple libraries which depend on p5.js in preview-frame.ts. It effectively implements option 3 described in https://github.com/toolness/p5.js-widget/issues/53#issuecomment-240387563.

The biggest volatility here is that it uses an undocumented feature of the p5 constructor whereby if a sketch function isn't passed in as the first argument, p5 will initialize itself in global mode. If we can make this a documented, supported use case in p5 core, that will ensure the widget continues to work as p5 matures. I've filed https://github.com/processing/p5.js/issues/1570 for this.

Thoughts @kaganjd ?

kaganjd commented 8 years ago

@toolness Awesome! I'm still wrapping my head around the concept and syntax here, but I get that this lets us call p5 global mode after we're sure everything else has loaded. Seems more elegant than a bunch of iframes too. I'll stay tuned for the response to processing/p5.js#1570 :)