storeItem value must be serializable, not "any type
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 24k
- Forks
- 3.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 25
Description
Most appropriate sections of the p5.js website?
Reference
What is your operating system?
Windows
Web browser and version
No response
Actual Behavior
The documentation of getItem() currently says:
The second parameter, value, is the value to be stored. Values can have any type.
However value can only accept JSON serializable values.
An example of a workaround to store an image could be added as an example, using toDataURL():
yourImage.canvas.toDataURL()
Expected Behavior
the text should be corrected to:
The second parameter, value, is the value to be stored. Values must be Serializable.
Steps to reproduce
let img;
preload() {
img = loadImage("myImage.png")
}
setup() {
storeItem("MyImage", img);
}
p5.min.js:2 Uncaught
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'r'
--- property '_pixelsState' closes the circle
at JSON.stringify (<anonymous>)
at n.default.storeItem (p5.min.js:2:554483)
at <anonymous>:1:1
Would you like to work on the issue?
I will work on it
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open the linked getItem() reference page and review the description of the value parameter. Correct the statement that values can have any type to require serializable values, and consider the proposed toDataURL() workaround example. Done means the reference no longer promises unsupported values and accurately describes the limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100