@nativewrappers/common 0.0.139 → 0.0.141

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.
@@ -4,7 +4,8 @@ type FunctionCall = (resource_name?: string) => void;
4
4
  declare class ResourceWrapper {
5
5
  #private;
6
6
  /**
7
- * Adds a function to get called whenever a resource is started
7
+ * Adds a function to get called whenever a resource is started, if the current
8
+ * {@link resource_name} is started then it will immediately call the function.
8
9
  * @param resource_name The resource name to add to the start listener.
9
10
  * @param fn The function to call
10
11
  */
@@ -20,7 +20,8 @@ class ResourceWrapper {
20
20
  }
21
21
  }
22
22
  /**
23
- * Adds a function to get called whenever a resource is started
23
+ * Adds a function to get called whenever a resource is started, if the current
24
+ * {@link resource_name} is started then it will immediately call the function.
24
25
  * @param resource_name The resource name to add to the start listener.
25
26
  * @param fn The function to call
26
27
  */
@@ -28,6 +29,9 @@ class ResourceWrapper {
28
29
  if (resource_name === "global") {
29
30
  this.#global_on_resource_start.push(fn);
30
31
  } else {
32
+ if (GetResourceState(resource_name) === "started") {
33
+ setImmediate(() => fn(resource_name));
34
+ }
31
35
  this.#add_or_init(this.#on_resource_start, resource_name, fn);
32
36
  }
33
37
  }
@@ -80,22 +84,16 @@ const GetResourceWrapper = /* @__PURE__ */ __name(() => {
80
84
  }, "GetResourceWrapper");
81
85
  EnsureResourceWrapperInit();
82
86
  const RESOURCE_WRAPPER = globalThis.RESOURCE_WRAPPER;
83
- const onResourceStart = /* @__PURE__ */ __name((resource, originalMethod) => {
84
- if (resource !== "global" && GetResourceState(resource) === "started") {
85
- setImmediate(() => originalMethod.call());
86
- }
87
- RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod);
88
- }, "onResourceStart");
89
87
  function OnResourceStart(resource = GetCurrentResourceName()) {
90
88
  return /* @__PURE__ */ __name(function actualDecorator(originalMethod, context) {
91
89
  if (context.private) {
92
90
  throw new Error("OnResourceStart does not work on private types, please mark the field as public");
93
91
  }
94
92
  if (context.static) {
95
- onResourceStart(resource, originalMethod);
93
+ RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod);
96
94
  } else {
97
95
  context.addInitializer(function() {
98
- onResourceStart(resource, originalMethod.bind(this));
96
+ RESOURCE_WRAPPER.add_to_resource_start(resource, originalMethod.bind(this));
99
97
  });
100
98
  }
101
99
  }, "actualDecorator");
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  ],
9
9
  "license": "MIT",
10
10
  "type": "module",
11
- "version": "0.0.139",
11
+ "version": "0.0.141",
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/nativewrappers/nativewrappers.git"