product_containers.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { product } from "./product.js";
  2. import { product_container } from "./product_container.js";
  3. export class product_containers {
  4. #content;
  5. #where;
  6. #inserted;
  7. constructor(where) {
  8. this.#where = where;
  9. this.#content = new Array();
  10. this.#inserted = new Array();
  11. }
  12. add_list(target) {
  13. target.forEach(count => {
  14. this.add(count);
  15. });
  16. return this;
  17. }
  18. add(target) {
  19. const current = new product_container(target);
  20. this.#content.push(current);
  21. return this;
  22. }
  23. clean() {
  24. this.#content = new Array();
  25. return this;
  26. }
  27. update() {
  28. this.#hide();
  29. setTimeout(() => {
  30. this.#content.forEach(count => {
  31. this.#inserted.push(count);
  32. count.add(this.#where);
  33. });
  34. }, 500);
  35. return this;
  36. }
  37. #hide() {
  38. this.#inserted.forEach(count => {
  39. if (!this.#content.includes(count)) {
  40. count.drop();
  41. }
  42. });
  43. this.#inserted = new Array();
  44. return this;
  45. }
  46. }