@mulsense/xnew 0.6.3 → 0.6.5

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.
@@ -6,7 +6,7 @@
6
6
 
7
7
  var xmatter = {
8
8
  initialize({} = {}) {
9
- xnew(Root, {});
9
+ xnew.promise(xnew(Root, {}));
10
10
  },
11
11
  get engine() {
12
12
  var _a;
@@ -3,7 +3,7 @@ import Matter from 'matter-js';
3
3
 
4
4
  var xmatter = {
5
5
  initialize({} = {}) {
6
- xnew(Root, {});
6
+ xnew.promise(xnew(Root, {}));
7
7
  },
8
8
  get engine() {
9
9
  var _a;
@@ -25,7 +25,7 @@
25
25
 
26
26
  var xpixi = {
27
27
  initialize({ canvas = null } = {}) {
28
- xnew(Root, { canvas });
28
+ xnew.promise(xnew(Root, { canvas }));
29
29
  },
30
30
  nest(object) {
31
31
  xnew(Nest, { object });
@@ -49,7 +49,10 @@
49
49
  xnew.promise(PIXI__namespace.autoDetectRenderer({
50
50
  width: canvas.width, height: canvas.height, view: canvas,
51
51
  antialias: true, backgroundAlpha: 0,
52
- })).then((value) => renderer = value);
52
+ })).then((value) => {
53
+ renderer = value;
54
+ xnew.resolve();
55
+ });
53
56
  let scene = new PIXI__namespace.Container();
54
57
  return {
55
58
  get renderer() { return renderer; },
@@ -3,7 +3,7 @@ import * as PIXI from 'pixi.js';
3
3
 
4
4
  var xpixi = {
5
5
  initialize({ canvas = null } = {}) {
6
- xnew(Root, { canvas });
6
+ xnew.promise(xnew(Root, { canvas }));
7
7
  },
8
8
  nest(object) {
9
9
  xnew(Nest, { object });
@@ -27,7 +27,10 @@ function Root(unit, { canvas }) {
27
27
  xnew.promise(PIXI.autoDetectRenderer({
28
28
  width: canvas.width, height: canvas.height, view: canvas,
29
29
  antialias: true, backgroundAlpha: 0,
30
- })).then((value) => renderer = value);
30
+ })).then((value) => {
31
+ renderer = value;
32
+ xnew.resolve();
33
+ });
31
34
  let scene = new PIXI.Container();
32
35
  return {
33
36
  get renderer() { return renderer; },
@@ -6,7 +6,7 @@
6
6
 
7
7
  var xrapier2d = {
8
8
  initialize({ gravity = { x: 0.0, y: -9.81 } } = {}) {
9
- xnew(Root, { gravity });
9
+ xnew.promise(xnew(Root, { gravity }));
10
10
  },
11
11
  get world() {
12
12
  var _a;
@@ -3,7 +3,7 @@ import RAPIER from '@dimforge/rapier2d-compat';
3
3
 
4
4
  var xrapier2d = {
5
5
  initialize({ gravity = { x: 0.0, y: -9.81 } } = {}) {
6
- xnew(Root, { gravity });
6
+ xnew.promise(xnew(Root, { gravity }));
7
7
  },
8
8
  get world() {
9
9
  var _a;
@@ -6,7 +6,7 @@
6
6
 
7
7
  var xrapier3d = {
8
8
  initialize({ gravity = { x: 0.0, y: -9.81, z: 0.0 } } = {}) {
9
- xnew(Root, { gravity });
9
+ xnew.promise(xnew(Root, { gravity }));
10
10
  },
11
11
  get world() {
12
12
  var _a;
@@ -3,7 +3,7 @@ import RAPIER from '@dimforge/rapier3d-compat';
3
3
 
4
4
  var xrapier3d = {
5
5
  initialize({ gravity = { x: 0.0, y: -9.81, z: 0.0 } } = {}) {
6
- xnew(Root, { gravity });
6
+ xnew.promise(xnew(Root, { gravity }));
7
7
  },
8
8
  get world() {
9
9
  var _a;
@@ -25,7 +25,7 @@
25
25
 
26
26
  var xthree = {
27
27
  initialize({ canvas = null, camera = null } = {}) {
28
- xnew(Root, { canvas, camera });
28
+ xnew.promise(xnew(Root, { canvas, camera }));
29
29
  },
30
30
  nest(object) {
31
31
  xnew(Nest, { object });
@@ -53,6 +53,7 @@
53
53
  renderer.setClearColor(0x000000, 0);
54
54
  camera = camera !== null && camera !== void 0 ? camera : new THREE__namespace.PerspectiveCamera(45, renderer.domElement.width / renderer.domElement.height);
55
55
  const scene = new THREE__namespace.Scene();
56
+ xnew.resolve();
56
57
  return {
57
58
  get canvas() { return canvas; },
58
59
  get camera() { return camera; },
@@ -3,7 +3,7 @@ import * as THREE from 'three';
3
3
 
4
4
  var xthree = {
5
5
  initialize({ canvas = null, camera = null } = {}) {
6
- xnew(Root, { canvas, camera });
6
+ xnew.promise(xnew(Root, { canvas, camera }));
7
7
  },
8
8
  nest(object) {
9
9
  xnew(Nest, { object });
@@ -31,6 +31,7 @@ function Root(unit, { canvas, camera }) {
31
31
  renderer.setClearColor(0x000000, 0);
32
32
  camera = camera !== null && camera !== void 0 ? camera : new THREE.PerspectiveCamera(45, renderer.domElement.width / renderer.domElement.height);
33
33
  const scene = new THREE.Scene();
34
+ xnew.resolve();
34
35
  return {
35
36
  get canvas() { return canvas; },
36
37
  get camera() { return camera; },
package/dist/xnew.d.ts CHANGED
@@ -20,14 +20,6 @@ declare class MapMap<Key1, Key2, Value> extends Map<Key1, Map<Key2, Value>> {
20
20
  delete(key1: Key1, key2: Key2): boolean;
21
21
  }
22
22
 
23
- interface TimerOptions {
24
- transition?: Function;
25
- timeout?: Function;
26
- duration: number;
27
- iterations: number;
28
- easing?: string;
29
- }
30
-
31
23
  declare class Eventor {
32
24
  private map;
33
25
  add(element: HTMLElement | SVGElement, type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
@@ -54,26 +46,23 @@ declare class Eventor {
54
46
  type UnitElement = HTMLElement | SVGElement;
55
47
  declare class UnitPromise {
56
48
  promise: Promise<any>;
57
- component: Function | null;
58
- constructor(promise: Promise<any>, component: Function | null);
49
+ Component: Function | null;
50
+ constructor(promise: Promise<any>, Component: Function | null);
59
51
  then(callback: Function): UnitPromise;
60
52
  catch(callback: Function): UnitPromise;
61
53
  finally(callback: Function): UnitPromise;
54
+ private wrap;
62
55
  }
63
56
  declare class UnitTimer {
64
57
  private unit;
65
58
  private stack;
66
- constructor(options: TimerOptions);
67
59
  clear(): void;
68
- timeout(timeout: Function, duration?: number): this;
69
- iteration(timeout: Function, duration?: number, iterations?: number): this;
70
- transition(transition: Function, duration?: number, easing?: string): this;
71
- static execute(timer: UnitTimer, options: TimerOptions): void;
72
- static next(timer: UnitTimer): void;
73
- static Component(unit: Unit, { options, snapshot }: {
74
- options: TimerOptions;
75
- snapshot: Snapshot;
76
- }): void;
60
+ timeout(callback: Function, duration?: number): UnitTimer;
61
+ interval(callback: Function, duration?: number, iterations?: number): UnitTimer;
62
+ transition(transition: Function, duration?: number, easing?: string): UnitTimer;
63
+ private static execute;
64
+ private static next;
65
+ private static Component;
77
66
  }
78
67
  interface Context {
79
68
  stack: Context | null;
@@ -103,6 +92,11 @@ interface Internal {
103
92
  ancestors: Unit[];
104
93
  children: Unit[];
105
94
  promises: UnitPromise[];
95
+ done: {
96
+ promise: Promise<any>;
97
+ resolve: Function;
98
+ reject: Function;
99
+ };
106
100
  nestElements: {
107
101
  element: UnitElement;
108
102
  owned: boolean;
@@ -133,7 +127,7 @@ declare class Unit {
133
127
  static finalize(unit: Unit): void;
134
128
  static nest(unit: Unit, target: UnitElement | string, textContent?: string | number): UnitElement;
135
129
  static currentComponent: Function;
136
- static extend(unit: Unit, component: Function, props?: Object): {
130
+ static extend(unit: Unit, Component: Function, props?: Object): {
137
131
  [key: string]: any;
138
132
  };
139
133
  static start(unit: Unit): void;
@@ -147,7 +141,7 @@ declare class Unit {
147
141
  static snapshot(unit: Unit): Snapshot;
148
142
  static context(unit: Unit, key: any, value?: any): any;
149
143
  static component2units: MapSet<Function, Unit>;
150
- static find(component: Function): Unit[];
144
+ static find(Component: Function): Unit[];
151
145
  static type2units: MapSet<string, Unit>;
152
146
  on(type: string, listener: Function, options?: boolean | AddEventListenerOptions): void;
153
147
  off(type?: string, listener?: Function): void;
@@ -158,20 +152,20 @@ declare class Unit {
158
152
 
159
153
  interface CreateUnit {
160
154
  /**
161
- * Creates a new Unit component
155
+ * creates a new Unit component
162
156
  * @param Component - component function
163
157
  * @param props - properties for component function
164
- * @returns A new Unit instance
158
+ * @returns a new Unit instance
165
159
  * @example
166
160
  * const unit = xnew(MyComponent, { data: 0 })
167
161
  */
168
162
  (Component?: Function | string, props?: Object): Unit;
169
163
  /**
170
- * Creates a new Unit component
164
+ * creates a new Unit component
171
165
  * @param target - HTMLElement | SVGElement, or HTML tag for new element
172
166
  * @param Component - component function
173
167
  * @param props - properties for component function
174
- * @returns A new Unit instance
168
+ * @returns a new Unit instance
175
169
  * @example
176
170
  * const unit = xnew(element, MyComponent, { data: 0 })
177
171
  * const unit = xnew('<div>', MyComponent, { data: 0 })
@@ -285,19 +279,21 @@ declare namespace xnew {
285
279
  }
286
280
  declare const xnew: CreateUnit & {
287
281
  nest(target: UnitElement | string): HTMLElement | SVGElement;
288
- extend(component: Function, props?: Object): {
282
+ extend(Component: Function, props?: Object): {
289
283
  [key: string]: any;
290
284
  };
291
285
  context(component: Function): any;
292
- promise(promise: Promise<any>): UnitPromise;
286
+ promise(promise: Promise<any> | Unit): UnitPromise;
293
287
  then(callback: Function): UnitPromise;
294
288
  catch(callback: Function): UnitPromise;
289
+ resolve(value?: any): void;
290
+ reject(reason?: any): void;
295
291
  finally(callback: Function): UnitPromise;
296
292
  scope(callback: any): any;
297
293
  find(component: Function): Unit[];
298
294
  emit(type: string, ...args: any[]): void;
299
- timeout(timeout: Function, duration?: number): UnitTimer;
300
- interval(timeout: Function, duration: number, iterations?: number): UnitTimer;
295
+ timeout(callback: Function, duration?: number): UnitTimer;
296
+ interval(callback: Function, duration: number, iterations?: number): UnitTimer;
301
297
  transition(transition: Function, duration?: number, easing?: string): UnitTimer;
302
298
  protect(): void;
303
299
  } & {