Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module syntax conversion #7257

Merged
merged 9 commits into from
Sep 12, 2024
Merged

Conversation

limzykenneth
Copy link
Member

I'm currently in the process of converting all modules that are not worked on by someone immediately into using the new module syntax, ie. not Typography, FES, or WebGL, these can be converted at the implementers' own discretion.

Do have a look at the already converted ones for guidance on how to convert or let me know if further clarifications are needed. I'll outline below.

Each folder inside src/ is considered a module (ie. if we were to distribute the library in modular form, these are not likely to be further split up). Each file inside of each module is considered a submodule/library file and uses the new library syntax as described in #7015. In addition, each module folder will have a new file index.js which comes in the form:

import arrayFunctions from './array_functions.js';
// ...

export default function(p5){
  p5.registerAddon(arrayFunctions);
  // ...
}

The bundler entry point app.js will then import these index file and pass p5 to the exported default function, kick starting the module linking process. To put it shortly, the convention/syntax described above plus some minor details I omitted here is to enable the different use cases needed. In addition to global mode and instance mode, the following:

ES6 modular import

import calculation from './src/math/calculation.js';
p5.registerAddon(calculation);

Script tag modular library import

<script src="./p5.js" />
<script src="./p5.math.js" />
<script src="./sketch.js" />

@limzykenneth limzykenneth marked this pull request as ready for review September 11, 2024 21:16
@limzykenneth limzykenneth merged commit d1d7f47 into processing:dev-2.0 Sep 12, 2024
1 of 2 checks passed
@limzykenneth limzykenneth linked an issue Sep 12, 2024 that may be closed by this pull request
21 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[p5.js 2.0 RFC Proposal]: Functional core and modular build
1 participant