onejs-core 1.0.13 → 1.0.14

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.
@@ -65,17 +65,21 @@ declare namespace CS {
65
65
  public includeGlobalObjects : boolean
66
66
  public constructor ()
67
67
  }
68
- class EngineHost extends System.Object implements System.IDisposable
68
+ interface IEngineHost {
69
+ add_onReload ($value: System.Action) : void
70
+ remove_onReload ($value: System.Action) : void
71
+ add_onDispose ($value: System.Action) : void
72
+ remove_onDispose ($value: System.Action) : void
73
+ }
74
+ class EngineHost extends System.Object implements System.IDisposable, IEngineHost
69
75
  {
70
76
  protected [__keep_incompatibility]: never;
71
- public add_onReload ($value: OneJS.EngineHost.ActionCallback) : void
72
- public remove_onReload ($value: OneJS.EngineHost.ActionCallback) : void
73
- public add_onDestroy ($value: OneJS.EngineHost.ActionCallback) : void
74
- public remove_onDestroy ($value: OneJS.EngineHost.ActionCallback) : void
77
+ public add_onReload ($value: System.Action) : void
78
+ public remove_onReload ($value: System.Action) : void
79
+ public add_onDispose ($value: System.Action) : void
80
+ public remove_onDispose ($value: System.Action) : void
75
81
  public subscribe ($eventSource: any, $eventName: string, $handler: Function) : System.Action
76
82
  public subscribe ($eventName: string, $handler: Function) : System.Action
77
- public InvokeOnReload () : void
78
- public InvokeOnDestroy () : void
79
83
  public Dispose () : void
80
84
  public constructor ($engine: OneJS.ScriptEngine)
81
85
  }
@@ -446,14 +450,6 @@ declare namespace CS {
446
450
  public constructor ()
447
451
  }
448
452
  }
449
- namespace OneJS.EngineHost {
450
- interface ActionCallback
451
- {
452
- () : void;
453
- Invoke?: () => void;
454
- }
455
- var ActionCallback: { new (func: () => void): ActionCallback; }
456
- }
457
453
  namespace Puerts {
458
454
  class GenericDelegate extends System.Object
459
455
  {
@@ -34,11 +34,14 @@ declare global {
34
34
  const cancelAnimationFrame: (id: number) => void
35
35
 
36
36
  const console: {
37
- log: (...args: any[]) => void
38
- error: (...args: any[]) => void
39
- warn: (...args: any[]) => void
40
- info: (...args: any[]) => void
41
- debug: (...args: any[]) => void
37
+ log: (...args: any[]) => void;
38
+ info: (...args: any[]) => void;
39
+ warn: (...args: any[]) => void;
40
+ error: (...args: any[]) => void;
41
+ trace: (...args: any[]) => void;
42
+ assert: (condition: boolean, ...args: any[]) => void;
43
+ time: (label: string) => void;
44
+ timeEnd: (label: string) => void;
42
45
  }
43
46
 
44
47
  interface Event {
@@ -12,13 +12,13 @@ declare namespace OneJS {
12
12
  declare const onejs: {
13
13
  add_onReload(handler: () => void): void
14
14
  remove_onReload(handler: () => void): void
15
- add_onDestroy(handler: () => void): void
16
- remove_onDestroy(handler: () => void): void
15
+ add_onDispose(handler: () => void): void
16
+ remove_onDispose(handler: () => void): void
17
17
 
18
- interop: { // TODO
19
- classes: Record<string, any>
20
- objects: Record<string, any>
21
- }
18
+ // interop: { // TODO
19
+ // classes: Record<string, any>
20
+ // objects: Record<string, any>
21
+ // }
22
22
 
23
23
  subscribe<T, K extends OneJS.EventKeys<T>>(
24
24
  eventSource: T,
@@ -7,3 +7,4 @@
7
7
  export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from "./color-parser";
8
8
  export { palettes } from "./color-palettes";
9
9
  export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser";
10
+ export { subscribe } from "./subscribe";
@@ -10,3 +10,4 @@ export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from
10
10
  export { palettes } from "./color-palettes";
11
11
  // @ts-ignore - prevent `allowImportingTsExtensions` error
12
12
  export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser";
13
+ export { subscribe } from "./subscribe";
@@ -0,0 +1,4 @@
1
+ export declare function subscribe<T, K extends keyof T>(target: T, eventName: K, callback: () => void): () => void;
2
+ export declare function subscribe<T, K extends keyof T>(target: {
3
+ new (): T;
4
+ }, eventName: K, callback: () => void): () => void;
@@ -0,0 +1,10 @@
1
+ import { Action, Delegate } from "System";
2
+ export function subscribe(target, eventName, callback) {
3
+ var action = new Action(callback);
4
+ target[eventName] = Delegate.Combine(target[eventName], action);
5
+ const unsubscribe = () => {
6
+ target[eventName] = Delegate.Remove(target[eventName], action);
7
+ };
8
+ onejs.add_onReload(unsubscribe);
9
+ return unsubscribe;
10
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "onejs-core",
3
3
  "description": "The JS part of OneJS, a UI framework and Scripting Engine for Unity.",
4
- "version": "1.0.13",
4
+ "version": "1.0.14",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./typings.d.ts",
7
7
  "dependencies": {
package/utils/index.ts CHANGED
@@ -11,3 +11,4 @@ export { parseColor, parseCSSColor, colorStrToF4, namedColor, namedColors } from
11
11
  export { palettes } from "./color-palettes"
12
12
  // @ts-ignore - prevent `allowImportingTsExtensions` error
13
13
  export { parseFloat2, parseFloat3, parseFloat4 } from "./float-parser"
14
+ export { subscribe } from "./subscribe"
@@ -0,0 +1,17 @@
1
+ import { Action, Delegate } from "System"
2
+
3
+
4
+ export function subscribe<T, K extends keyof T>(target: T, eventName: K, callback: () => void): () => void
5
+ export function subscribe<T, K extends keyof T>(target: { new(): T }, eventName: K, callback: () => void): () => void
6
+ export function subscribe(target: any, eventName: any, callback: () => void): () => void {
7
+ var action = new Action(callback)
8
+ target[eventName] = Delegate.Combine(target[eventName] as any, action) as any
9
+
10
+ const unsubscribe = () => {
11
+ target[eventName] = Delegate.Remove(target[eventName] as any, action) as any
12
+ }
13
+
14
+ onejs.add_onReload(unsubscribe)
15
+
16
+ return unsubscribe
17
+ }