@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.
@@ -32,25 +32,32 @@
32
32
  get [Symbol.toStringTag]() {
33
33
  return this.constructor.name;
34
34
  }
35
- /**
36
- * The same handler will only be registered once.
37
- */
38
- on(event, handler) {
35
+ on(event, listener) {
39
36
  if (!this.map.has(event)) {
40
37
  this.map.set(event, new Set());
41
38
  }
42
39
  const set = this.map.get(event);
43
40
  set.add(handler);
44
- }
45
- off(event, handler) {
46
- if (!this.map.has(event))
47
- return;
48
- const handlers = this.map.get(event);
49
- handlers.delete(handler);
50
- if (handlers.size === 0) {
51
- this.map.delete(event);
41
+ return () => {
42
+ if (!this.map.has(event))
43
+ return;
44
+ const handlers = this.map.get(event);
45
+ handlers.delete(handler);
46
+ if (handlers.size === 0) {
47
+ this.map.delete(event);
48
+ }
49
+ };
50
+ function handler(...args) {
51
+ listener(...args);
52
52
  }
53
53
  }
54
+ once(event, listener) {
55
+ const removeListener = this.on(event, (...args) => {
56
+ listener(...args);
57
+ removeListener();
58
+ });
59
+ return removeListener;
60
+ }
54
61
  emit(event, ...args) {
55
62
  if (!this.map.has(event))
56
63
  return;
@@ -7557,6 +7564,24 @@
7557
7564
  get [Symbol.toStringTag]() {
7558
7565
  return this.constructor.name;
7559
7566
  }
7567
+ *entries() {
7568
+ yield* dfs(this.root, []);
7569
+ function* dfs(node, paths) {
7570
+ for (const [path, childNode] of node.children) {
7571
+ const newPaths = [...paths, path];
7572
+ if (es2018$2.isntUndefined(childNode.value)) {
7573
+ yield [newPaths, childNode.value];
7574
+ }
7575
+ yield* dfs(childNode, newPaths);
7576
+ }
7577
+ }
7578
+ }
7579
+ keys() {
7580
+ return es2018$4.map(this.entries(), ([key]) => key);
7581
+ }
7582
+ values() {
7583
+ return es2018$4.map(this.entries(), ([_, value]) => value);
7584
+ }
7560
7585
  set(key, value) {
7561
7586
  let node = this.root;
7562
7587
  for (const part of key) {