UNPKG

@studiometa/js-toolkit

Version:

A set of useful little bits of JavaScript to boost your project! 🚀

40 lines (39 loc) • 964 B
function groups() { return globalThis.__JS_TOOLKIT_GROUPS__ ??= /* @__PURE__ */ new Map(); } function withGroup(BaseClass, namespace = "") { return class WithGroup extends BaseClass { static config = { ...BaseClass.config, options: { group: String } }; /** * Get the group set. */ get $group() { const group = `${namespace}${this.$options.group}`; const instances = groups().get(group) ?? groups().set(group, /* @__PURE__ */ new Set()).get(group); for (const instance of instances) { if (!instance.$el.isConnected) { instances.delete(instance); } } return instances; } constructor(element) { super(element); this.$on("mounted", () => { this.$group.add(this); }); this.$on("destroyed", () => { this.$group.delete(this); }); } }; } export { withGroup }; //# sourceMappingURL=withGroup.js.map