Issue 9100 - #9116
Conversation
…rs more beginner friendly
…ts on canvas when updating the describe functions.
Continuous ReleaseCDN linkPublished PackagesCommit hash: 6cfaf8a Previous deploymentsThis is an automated message. |
| * | ||
| * @method describe | ||
| * @param {String} text description of the canvas. | ||
| * @param {(FALLBACK|LABEL|String)} [langOrDisplay] valid lang attribute or either LABEL or FALLBACK. |
There was a problem hiding this comment.
Do we have this pattern anywhere else? I'm not remembering anything off the top of my head. But it's quite a challenging pattern. cc @perminder-17 sorry if it was already discussed somewhere and I missed it, but my thoughts below.
From your examples:
describe('text')
describe('text', LABEL)
describe('text', 'en')
describe('text', 'en', LABEL)
describe('text', LABEL, 'en')
So the second one is lang or display also? Maybe it should be parameter1 and parameter2 and either can be lang or display but to be honest if we dont already have precedent for this kind of approach, I am a little worried about it being very confusing for learners, and resulting in outdated documentation for contributors.
| if (typeof text !== 'string') { | ||
| return; | ||
| } | ||
| const parsedOptions = _parseOptions(this, langOrDisplay, display); |
There was a problem hiding this comment.
To avoid duplication of this code, you can use decorators. For example, here how we use decorators for v ector validation, where very similar code runs for each of the vector binary operations: https://github.com/processing/p5.js/blob/main/src/math/patch-vector.js we wanted to avoid copy-pasting the same code in 5 places, and we used that decorator pattern instead. Firendly Errors also use decorators. Please do try using this pattern to avoid this option interpretation (even though in your case its just 2 places); the decorators API was recently added so don't hesitate to @ me on discord for help with this one.
|
Thanks @ksen0 for the feedback! I thought it would be beginner friendly to make it, like you said, As for the decorator API, am I understanding this correctly? I'd like to confirm the preferred syntax of the describe/describeElement functions before working on a decorator for the optional parameters. |
Resolves #9100
Changes:
API Changes:
_parseOptionswas made to help determine what optional parameters are used.innerso to allow sketch creators to have multiple sketches with multiple lang attributes (otherwise, one lang attribute would override all the others).Order of optional parameters doesn't matter so that it's beginner friendly.
Manual Test Page:
Unit Tests and JSDoc Updates:
Screenshots of the change:
screen-reader-lang-test.mp4
I tried my best to showcase Windows Narrator working reading the describe() functions. The behavior of the screen reader works as expected for each of the tests (5 sketch tests for the parameter combinations and 1 sketch test to show that without the lang attribute, the screen reader skips native script text).
The failed test is typography test which still failed in the main branch.
PR Checklist
npm run lintpasses