File tree Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Expand file tree Collapse file tree 1 file changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,35 @@ import { assertInjector } from 'ngxtension/assert-injector';
3
3
import { injectStore } from '../store' ;
4
4
import { NgtBeforeRenderRecord } from '../types' ;
5
5
6
+ /**
7
+ * `injectBeforeRender` invokes its callback on every frame. Hence, the notion of tracking
8
+ * changes (i.e: signals) does not really matter since we're getting latest values of the things we need on every frame anyway.
9
+ *
10
+ * If `priority` is dynamic, consumers should set up `injectBeforeRender` in
11
+ * an `effect` and track `priority` changes. Make use of `onCleanup` to clean up
12
+ * previous before render subscription
13
+ *
14
+ * @example
15
+ * ```ts
16
+ * const injector = inject(Injector);
17
+ *
18
+ * effect((onCleanup) => {
19
+ * const priority = this.priority(); // track priority
20
+ *
21
+ * const sub = injectBeforeRender(
22
+ * ({ gl, camera }) => {
23
+ * // before render logic
24
+ * },
25
+ * {
26
+ * priority,
27
+ * injector, // injector is needed since injectBeforeRender is invoked in effect body
28
+ * }
29
+ * });
30
+ *
31
+ * onCleanup(() => sub());
32
+ * });
33
+ * ```
34
+ */
6
35
export function injectBeforeRender (
7
36
cb : NgtBeforeRenderRecord [ 'callback' ] ,
8
37
{ priority = 0 , injector } : { priority ?: number ; injector ?: Injector } = { } ,
You can’t perform that action at this time.
0 commit comments