Skip to content

Conversation

@hxrshxz
Copy link
Contributor

@hxrshxz hxrshxz commented Oct 22, 2025

Resolves #8151

Changes:

Marked both the static and instance version of the array() method as deprecated

PR Checklist

* </div>
*/
array() {
p5._friendlyError(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently throwing errors in the tests. Inside of classes, we don't have access to a global p5. We do have access to them in the exported addon function body though. In #8176 I dealt with something similar by patching the class in the exported addon function to give it access to these.

Also, once this does work, we probably don't want to flood the user's console with logs if they're using this a bunch every frame. We should maybe track whether or not we've logged this warning yet, and don't log it a second time.

Copy link
Contributor Author

@hxrshxz hxrshxz Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your help sharing this pattern made the fix super easy

@hxrshxz hxrshxz force-pushed the deprecate-array-vector branch 2 times, most recently from a333725 to 4201812 Compare October 22, 2025 22:25
@hxrshxz hxrshxz requested a review from davepagurek October 22, 2025 23:13
@sidwellr
Copy link

As long as this is being changed, I suggest updating the documentation as well. Change from "Returns the vector's components as an array of numbers" to something like "Returns the vector's first three components as an array of three numbers." The existing example is great; it makes clear that the result will have three numbers even for a 2D array.

I also suggest including a pointer to its replacement in the deprecation message (and perhaps something similar in the FES message):

@deprecated array() will be removed in a future version of p5.js; use the more flexible v.values instead of v.array()

Copilot AI review requested due to automatic review settings December 16, 2025 10:51
@hxrshxz
Copy link
Contributor Author

hxrshxz commented Dec 16, 2025

@davepagurek please have a look , thank you

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR marks the array() method in p5.Vector as deprecated, addressing issue #8151. It adds runtime deprecation warnings using p5._friendlyError to notify users that the method will be removed in a future version. This is the first deprecation in p5.js to include runtime warnings, establishing a new pattern beyond just JSDoc annotations.

Key Changes:

  • Added @deprecated JSDoc tags to both instance and static array() methods
  • Implemented a deprecation warning system that shows a friendly error message once per session
  • Created _showArrayDeprecationWarning() helper method to manage the warning display

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants