Store.js 677 B

12345678910111213141516171819202122232425262728293031323334353637
  1. const stores = {};
  2. /** @internal */
  3. export class Store {
  4. constructor(kp) {
  5. this.kp = kp;
  6. this.data = {};
  7. }
  8. static resolve(kp) {
  9. if (!stores[kp]) {
  10. stores[kp] = new Store(kp);
  11. }
  12. return stores[kp];
  13. }
  14. clear() {
  15. this.data = {};
  16. }
  17. drop() {
  18. this.clear();
  19. delete stores[this.kp];
  20. }
  21. get(key) {
  22. return this.data[key];
  23. }
  24. key(idx) {
  25. return this.keys()[idx];
  26. }
  27. keys() {
  28. return Object.keys(this.data);
  29. }
  30. rm(k) {
  31. delete this.data[k];
  32. }
  33. set(k, v) {
  34. this.data[k] = v;
  35. }
  36. }
  37. //# sourceMappingURL=Store.js.map