@armoury/fivem-framework-common 1.0.47 → 1.0.48

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,7 @@ exports.UIListener = UIListener;
4
4
  exports.UIListeners = UIListeners;
5
5
  const decorator_utils_1 = require("./decorator.utils");
6
6
  function UIListener(data) {
7
- return function (target, propertyKey) {
7
+ return function (target, propertyKey, _descriptor) {
8
8
  const eventName = (data === null || data === void 0 ? void 0 : data.eventName) || propertyKey;
9
9
  Reflect.defineMetadata(`arm_uiListener_${propertyKey}`, { eventName }, target);
10
10
  };
@@ -16,9 +16,17 @@ function UIListeners(target, _prototype, providers) {
16
16
  const { eventName } = mapping.value;
17
17
  const func = mapping.key.split('_').slice(2).join('_');
18
18
  Cfx.Client.RegisterNuiCallbackType(eventName);
19
- Cfx.Client.on('__cfx_nui:' + eventName, (data, cb) => {
20
- mapping.target[func].call(mapping.target, data);
21
- cb('ok');
19
+ Cfx.Client.on('__cfx_nui:' + eventName, async (data, cb) => {
20
+ const result = await mapping.target[func].call(mapping.target, data);
21
+ if (result === undefined) {
22
+ cb({ ok: true });
23
+ }
24
+ else if (result !== null && typeof result === 'object') {
25
+ cb(result);
26
+ }
27
+ else {
28
+ cb({ response: result });
29
+ }
22
30
  });
23
31
  });
24
32
  }
@@ -1,6 +1,6 @@
1
1
  import { DecoratorUtils } from "./decorator.utils";
2
2
  export function UIListener(data) {
3
- return function (target, propertyKey) {
3
+ return function (target, propertyKey, _descriptor) {
4
4
  const eventName = (data === null || data === void 0 ? void 0 : data.eventName) || propertyKey;
5
5
  Reflect.defineMetadata(`arm_uiListener_${propertyKey}`, { eventName }, target);
6
6
  };
@@ -12,9 +12,17 @@ export function UIListeners(target, _prototype, providers) {
12
12
  const { eventName } = mapping.value;
13
13
  const func = mapping.key.split('_').slice(2).join('_');
14
14
  Cfx.Client.RegisterNuiCallbackType(eventName);
15
- Cfx.Client.on('__cfx_nui:' + eventName, (data, cb) => {
16
- mapping.target[func].call(mapping.target, data);
17
- cb('ok');
15
+ Cfx.Client.on('__cfx_nui:' + eventName, async (data, cb) => {
16
+ const result = await mapping.target[func].call(mapping.target, data);
17
+ if (result === undefined) {
18
+ cb({ ok: true });
19
+ }
20
+ else if (result !== null && typeof result === 'object') {
21
+ cb(result);
22
+ }
23
+ else {
24
+ cb({ response: result });
25
+ }
18
26
  });
19
27
  });
20
28
  }
@@ -1,4 +1,4 @@
1
1
  export declare function UIListener(data?: {
2
2
  eventName?: string;
3
- }): (target: any, propertyKey: string) => void;
3
+ }): <T extends (...args: any[]) => any>(target: any, propertyKey: string, _descriptor: TypedPropertyDescriptor<T> & (Parameters<T> extends [object, ...unknown[]] ? unknown : never)) => void;
4
4
  export declare function UIListeners(target: any, _prototype: any, providers?: Object[]): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@armoury/fivem-framework-common",
3
- "version": "1.0.47",
3
+ "version": "1.0.48",
4
4
  "description": "Shared APIs for the Armoury FiveM framework",
5
5
  "main": "dist/cjs/common/index.js",
6
6
  "module": "dist/esm/common/index.js",