Skip to content

Add instanceIndex alias for instanceID#8912

Merged
davepagurek merged 5 commits into
processing:mainfrom
aashu2006:instance-index-alias
Jun 20, 2026
Merged

Add instanceIndex alias for instanceID#8912
davepagurek merged 5 commits into
processing:mainfrom
aashu2006:instance-index-alias

Conversation

@aashu2006

@aashu2006 aashu2006 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Addresses #8911

Changes

  • Add instanceIndex as a value-based API for accessing the current instance index in p5.strands
  • Preserve instanceID() for backwards compatibility
  • Update docs and examples to use instanceIndex as the preferred API
  • Update WebGL and WebGPU tests to use instanceIndex

instanceIndex is exposed as a property rather than a function, making it feel more consistent with other strands values such as width, height, and mouseX. The existing instanceID() API remains available for compatibility.

PR Checklist

  • npm run lint passes
  • Inline reference is included / updated
  • Unit tests are included / updated

@aashu2006

Copy link
Copy Markdown
Contributor Author

@davepagurek I have updated it based on the discussion around instanceIndex.

instanceIndex is now exposed as a value instead of a function, while instanceID() remains unchanged for compatibility. The implementation uses a dedicated property accessor that creates the same underlying node as instanceID(), and docs/examples have been updated to use the value-based API.

@perminder-17 perminder-17 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for your work, the basic structure looks fine! I'll take a look and test it soon.

@aashu2006 aashu2006 force-pushed the instance-index-alias branch from ec6c04c to dd6bf34 Compare June 16, 2026 21:43
@aashu2006

Copy link
Copy Markdown
Contributor Author

I've fixed the CI failure and pushed an update, the issue was related to TypeScript type generation from the JSDoc annotations. Local test:types now passes.

@p5-bot

p5-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: f078104

Previous deployments

dd6bf34


This is an automated message.

@davepagurek davepagurek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good overall, just two minor things!

Comment thread src/strands/p5.strands.js
/**
* @method instanceID
* @beta
* @description

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we want to mark this as @deprecated Prefer using instanceIndex or something similar?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Comment thread test/unit/webgl/p5.Shader.js Outdated
assert.strictEqual(w, myp5.width);
});

test('instanceIndex is a value and instanceID() is a compatibility alias', () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like this + the test above are not indented, let's make them match the tests around them

@aashu2006 aashu2006 force-pushed the instance-index-alias branch from dd6bf34 to b969838 Compare June 20, 2026 16:49
@davepagurek davepagurek merged commit 71d062a into processing:main Jun 20, 2026
5 of 6 checks passed
vamshi567bh pushed a commit to vamshi567bh/p5.js that referenced this pull request Jun 20, 2026
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