processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.11k stars 3.22k forks source link

`p5.prototype.clearStorage` clears all items for the current domain, instead of items set with `storeItem` only #7003

Closed IronBlood closed 1 month ago

IronBlood commented 2 months ago

Most appropriate sub-area of p5.js?

p5.js version

No response

Web browser and version

No response

Operating system

No response

Steps to reproduce this

Code with comments are shown below. There should be a better way to handle with it, to avoid removing data set by other libraries or developers.

/**
 *
 * Clears all local storage items set with storeItem()
 * for the current domain.
 *
 * @method clearStorage
 * @for p5
 *
 */
p5.prototype.clearStorage = function() {
  localStorage.clear();
};
seralichtenhahn commented 1 month ago

@IronBlood I agree, clearStorage() should only remove items set by storeItem(). I can see that storeItem() also sets an additional item where the type of the value is stored. These helper items are all suffixed with "p5TypeID". That means there is a way of easily identifying all items set by storeItem().

I'm happy to open a PR with the implementation @limzykenneth

limzykenneth commented 1 month ago

@seralichtenhahn You can go ahead with a fix to match the documented behaviour. Thanks.