@blackglory/structures 0.5.1 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,25 +26,32 @@ class Emitter {
26
26
  get [Symbol.toStringTag]() {
27
27
  return this.constructor.name;
28
28
  }
29
- /**
30
- * The same handler will only be registered once.
31
- */
32
- on(event, handler) {
29
+ on(event, listener) {
33
30
  if (!this.map.has(event)) {
34
31
  this.map.set(event, new Set());
35
32
  }
36
33
  const set = this.map.get(event);
37
34
  set.add(handler);
38
- }
39
- off(event, handler) {
40
- if (!this.map.has(event))
41
- return;
42
- const handlers = this.map.get(event);
43
- handlers.delete(handler);
44
- if (handlers.size === 0) {
45
- this.map.delete(event);
35
+ return () => {
36
+ if (!this.map.has(event))
37
+ return;
38
+ const handlers = this.map.get(event);
39
+ handlers.delete(handler);
40
+ if (handlers.size === 0) {
41
+ this.map.delete(event);
42
+ }
43
+ };
44
+ function handler(...args) {
45
+ listener(...args);
46
46
  }
47
47
  }
48
+ once(event, listener) {
49
+ const removeListener = this.on(event, (...args) => {
50
+ listener(...args);
51
+ removeListener();
52
+ });
53
+ return removeListener;
54
+ }
48
55
  emit(event, ...args) {
49
56
  if (!this.map.has(event))
50
57
  return;
@@ -7551,6 +7558,24 @@ class TrieMap {
7551
7558
  get [Symbol.toStringTag]() {
7552
7559
  return this.constructor.name;
7553
7560
  }
7561
+ *entries() {
7562
+ yield* dfs(this.root, []);
7563
+ function* dfs(node, paths) {
7564
+ for (const [path, childNode] of node.children) {
7565
+ const newPaths = [...paths, path];
7566
+ if (es2018$2.isntUndefined(childNode.value)) {
7567
+ yield [newPaths, childNode.value];
7568
+ }
7569
+ yield* dfs(childNode, newPaths);
7570
+ }
7571
+ }
7572
+ }
7573
+ keys() {
7574
+ return es2018$4.map(this.entries(), ([key]) => key);
7575
+ }
7576
+ values() {
7577
+ return es2018$4.map(this.entries(), ([_, value]) => value);
7578
+ }
7554
7579
  set(key, value) {
7555
7580
  let node = this.root;
7556
7581
  for (const part of key) {