angular-three 4.0.0-next.13 → 4.0.0-next.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.
|
@@ -3008,32 +3008,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.4", ngImpor
|
|
|
3008
3008
|
* `injectBeforeRender` invokes its callback on every frame. Hence, the notion of tracking
|
|
3009
3009
|
* changes (i.e: signals) does not really matter since we're getting latest values of the things we need on every frame anyway.
|
|
3010
3010
|
*
|
|
3011
|
-
* If `priority` is
|
|
3012
|
-
* an `effect` and track `priority` changes. Make use of `onCleanup` to clean up
|
|
3013
|
-
* previous before render subscription
|
|
3011
|
+
* If `priority` is a Signal, `injectBeforeRender` will set up an Effect internally and returns the `EffectRef#destroy` instead.
|
|
3014
3012
|
*
|
|
3015
3013
|
* @example
|
|
3016
3014
|
* ```ts
|
|
3017
|
-
* const
|
|
3018
|
-
*
|
|
3019
|
-
*
|
|
3020
|
-
*
|
|
3021
|
-
*
|
|
3022
|
-
*
|
|
3023
|
-
*
|
|
3024
|
-
*
|
|
3025
|
-
* },
|
|
3026
|
-
* {
|
|
3027
|
-
* priority,
|
|
3028
|
-
* injector, // injector is needed since injectBeforeRender is invoked in effect body
|
|
3029
|
-
* }
|
|
3030
|
-
* });
|
|
3031
|
-
*
|
|
3032
|
-
* onCleanup(() => sub());
|
|
3033
|
-
* });
|
|
3015
|
+
* const destroy = injectBeforeRender(
|
|
3016
|
+
* ({ gl, camera }) => {
|
|
3017
|
+
* // before render logic
|
|
3018
|
+
* },
|
|
3019
|
+
* {
|
|
3020
|
+
* priority: this.priority, // this.priority is a Signal<number>
|
|
3021
|
+
* }
|
|
3022
|
+
* )
|
|
3034
3023
|
* ```
|
|
3035
3024
|
*/
|
|
3036
3025
|
function injectBeforeRender(cb, { priority = 0, injector } = {}) {
|
|
3026
|
+
if (typeof priority === 'function') {
|
|
3027
|
+
const effectRef = assertInjector(injectBeforeRender, injector, () => {
|
|
3028
|
+
const store = injectStore();
|
|
3029
|
+
const ref = effect((onCleanup) => {
|
|
3030
|
+
const p = priority();
|
|
3031
|
+
const sub = store.snapshot.internal.subscribe(cb, p, store);
|
|
3032
|
+
onCleanup(() => sub());
|
|
3033
|
+
});
|
|
3034
|
+
inject(DestroyRef).onDestroy(() => void ref.destroy());
|
|
3035
|
+
return ref;
|
|
3036
|
+
});
|
|
3037
|
+
return effectRef.destroy.bind(effectRef);
|
|
3038
|
+
}
|
|
3037
3039
|
return assertInjector(injectBeforeRender, injector, () => {
|
|
3038
3040
|
const store = injectStore();
|
|
3039
3041
|
const sub = store.snapshot.internal.subscribe(cb, priority, store);
|