Skip to content

Commit ce80683

Browse files
Chau TranChau Tran
Chau Tran
authored and
Chau Tran
committed
docs: update documentation
1 parent bdb9a07 commit ce80683

File tree

18 files changed

+1781
-1961
lines changed

18 files changed

+1781
-1961
lines changed

apps/documentation/docs/api/additional-exports.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class SceneGraph {
2020
:::info
2121

2222
`injectBeforeRender()` automatically cleans up the before render but it returns the reference to the clean up function.
23-
We can call this function anytime to clean up the before render, not just in `ngOnDestroy`
23+
We can call this function anytime to clean up the before render
2424

2525
:::
2626

apps/documentation/docs/api/custom-renderer.mdx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ To register a callback in the animation loop, we can listen for `(beforeRender)`
275275

276276
```ts
277277
@Component({
278-
template: `<ngt-mesh (beforeRender)="onBeforeRender($any($event))" />`,
278+
template: `<ngt-mesh (beforeRender)="onBeforeRender($event)" />`,
279279
})
280280
export class SceneGraph {
281281
onBeforeRender(event: NgtBeforeRenderEvent<Mesh>) {
@@ -286,10 +286,6 @@ export class SceneGraph {
286286

287287
When the element is destroyed, `(beforeRender)` is unregistered automatically.
288288

289-
:::note
290-
We use `$any($event)` because of Angular limitations on `CUSTOM_ELEMENTS_SCHEMA`
291-
:::
292-
293289
#### Render Priority
294290

295291
By default, NGT renders the scene on every frame. If we need to control this process, we can pass `priority` as **Attribute Binding** with number-string values
@@ -298,8 +294,8 @@ to any object whose `(beforeRender)` is being listened to. When a `priority` is
298294
```ts
299295
@Component({
300296
template: `
301-
<ngt-mesh priority="1" (beforeRender)="onBeforeRender($any($event))" />
302-
<ngt-mesh priority="2" (beforeRender)="onOtherBeforeRender($any($event))" />
297+
<ngt-mesh priority="1" (beforeRender)="onBeforeRender($event)" />
298+
<ngt-mesh priority="2" (beforeRender)="onOtherBeforeRender($event)" />
303299
`,
304300
})
305301
export class SceneGraph {
@@ -324,7 +320,7 @@ This event emits after the child **has been attached** to the parent
324320
@Component({
325321
template: `
326322
<ngt-mesh>
327-
<ngt-mesh-basic-material attach="material" (afterAttach)="onAfterAttach($any($event))" />
323+
<ngt-mesh-basic-material attach="material" (afterAttach)="onAfterAttach($event)" />
328324
</ngt-mesh>
329325
`,
330326
})
@@ -339,7 +335,7 @@ This event emits after an object is updated
339335

340336
```ts
341337
@Component({
342-
template: ` <ngt-mesh (afterUpdate)="onAfterUpdate($any($event))" [position]="[0, 1, 2]" /> `,
338+
template: ` <ngt-mesh (afterUpdate)="onAfterUpdate($event)" [position]="[0, 1, 2]" /> `,
343339
})
344340
export class SceneGraph {
345341
onAfterUpdate(event: Mesh) {}

apps/documentation/docs/api/pipes/push.mdx

Lines changed: 0 additions & 24 deletions
This file was deleted.

apps/documentation/docs/api/primitive.mdx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ A more realistic use-case is to load a 3D model into our SceneGraph
2323

2424
```ts
2525
@Component({
26-
template: ` <ngt-primitive *args="[model$ | ngtPush]" [scale]="0.01" /> `,
27-
imports: [NgtArgs, NgtPush],
26+
template: ` <ngt-primitive *args="[model()]" [scale]="0.01" /> `,
27+
imports: [NgtArgs],
2828
})
2929
export class SceneGraph {
30-
readonly model$ = injectNgtLoader(GLTFLoader, 'assets/model.glb').pipe(map((model) => model.scene));
30+
readonly #gltf = injectNgtLoader(
31+
() => GLTFLoader,
32+
() => 'assets/model.glb'
33+
);
34+
readonly model = computed(() => {
35+
const gltf = this.#gltf();
36+
if (!gltf) return null;
37+
return gltf.scene;
38+
});
3139
}
3240
```

apps/documentation/docs/api/ref.mdx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ The NGT Custom Renderer will assign the `Mesh` object to the `ref.nativeElement`
5959
returns an `NgtInjectedRef<ObjectType>`.
6060

6161
```ts
62-
type Subscribe<T> = (callback: (current: T, previous: T | null) => void) => Subscription;
63-
64-
export type NgtInjectedRef<T> = ElementRef<T> & {
65-
/* a Subscribe fn that emits current and previous value. Useful for debug */
66-
subscribe: Subscribe<T>;
67-
/* consumers should use this for listening to value of this ref. This filters out initial null value */
68-
$: Observable<T>;
62+
export type NgtInjectedRef<TElement> = ElementRef<TElement> & {
6963
/* consumers should use this for listenting to children changes on this ref */
70-
children$: (type?: 'objects' | 'nonObjects' | 'both') => Observable<NgtInstanceNode[]>;
71-
/* notify this CD when ref value changes */
72-
useCDR: (cdr: ChangeDetectorRef) => void;
64+
children: (type?: 'objects' | 'nonObjects' | 'both') => Signal<NgtInstanceNode[]>;
65+
/* consumers should use this to read the ref current value without registering the signal */
66+
untracked: TElement;
7367
};
7468
```
69+
70+
:::note
71+
72+
`NgtInjectedRef<TElement>#nativeElement` is overridden to be a getter that returns a `Signal<TElement>`. Consumers should use
73+
`nativeElement` only if they want to register `Signal<TElement>` as a dependency in other Signal APIs like `computed` or `effect`
74+
75+
:::

apps/documentation/docs/api/store.mdx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ title: Store
44
sidebar_label: Store
55
---
66

7-
`NgtStore` contains all information about the current `NgtCanvas`. `NgtStore` extends [RxState](https://www.rx-angular.io/docs/state/api/rx-state) API
7+
`NgtStore` contains all information about the current `NgtCanvas`. `NgtStore` utilizes [Angular Signals](https://angular.io/guide/signals).
88

99
```ts
1010
@Component({
1111
/*...*/
1212
})
1313
export class SceneGraph {
1414
// inject the Store. We can also use Constructor DI
15-
readonly store = inject(NgtStore);
15+
readonly #store = inject(NgtStore);
1616
}
1717
```
1818

@@ -23,9 +23,9 @@ export class SceneGraph {
2323
/*...*/
2424
})
2525
export class SceneGraph {
26-
readonly store = inject(NgtStore);
27-
readonly camera$ = this.store.select('camera'); // Observable<NgtCamera>
28-
readonly glDom$ = this.store.select('gl', 'domElement'); // Observable<HTMLElement>
26+
readonly #store = inject(NgtStore);
27+
readonly camera = this.#store.select('camera'); // Signal<NgtCamera>
28+
readonly glDom = this.#store.select('gl', 'domElement'); // Signal<HTMLElement>
2929
}
3030
```
3131

@@ -36,9 +36,9 @@ export class SceneGraph {
3636
/*...*/
3737
})
3838
export class SceneGraph {
39-
readonly store = inject(NgtStore);
40-
readonly camera = this.store.get('camera'); // NgtCamera
41-
readonly glDom = this.store.get('gl', 'domElement'); // HTMLElement
39+
readonly #store = inject(NgtStore);
40+
readonly camera = this.#store.get('camera'); // NgtCamera
41+
readonly glDom = this.#store.get('gl', 'domElement'); // HTMLElement
4242
}
4343
```
4444

@@ -51,19 +51,14 @@ Beside using `(beforeRender)` Output on Custom Element tags, we can also use `Ng
5151
/*...*/
5252
})
5353
export class SceneGraph {
54-
readonly store = inject(NgtStore);
55-
56-
private sub?: () => void;
54+
readonly #store = inject(NgtStore);
55+
readonly #destroyRef = inject(DestroyRef);
5756

5857
ngOnInit() {
5958
// register and return the clean up function
6059
// signature: subscribe(callback, priority)
61-
this.sub = this.store.get('internal').subscribe(() => {}, 0);
62-
}
63-
64-
ngOnDestroy() {
65-
// call the clean up function to unregister the callback
66-
this.sub?.();
60+
const sub = this.#store.get('internal').subscribe(() => {}, 0);
61+
this.#destroyRef.onDestroy(() => sub());
6762
}
6863
}
6964
```

0 commit comments

Comments
 (0)