processing / processing/p5.js

[p5.js 2.0] ESM usage in global mode

Open
#7,670 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Area:Core Discussion Enhancement
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Increasing access

existing feature in v2

Most appropriate sub-area of p5.js?
  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)
Feature enhancement details

In issue #7332 @limzykenneth wrote:

p5.js 2.0 will support ESM and due to the nature of ESM, sketches have to be written in instance mode. The way we are testing and iterating in 2.0 development is using an ESM sketch.

I understand that since functions declared in a module are not attached to the window, only the module's scope, users would have to define functions using the p5 v2 instance.

Yet, p5 v2 could otherwise start in global mode by attaching p5 instance functions and variables to window, which would make them top-level accessible in the module.

Ideally global mode would be the default when p5 v2 is used in an ESM module, or at least it should be an option, otherwise all p5 functions and vars would need to be instance prefixed.

I'm planning on making q5.js WebGPU top level global mode in an ESM the default way to use q5play (upcoming sequel to p5play), so it'd be great if p5 v2 supported this as well.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked discussion in issue #7332 and the described p5.js 2.0 ESM sketch usage. Clarify whether global mode should be the default or an opt-in option, then validate the chosen behavior with an ESM sketch; done means p5 functions and variables work as specified without unintended instance-mode requirements.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.