angular-three 4.0.0-next.13 → 4.0.0-next.15

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.
@@ -82,9 +82,9 @@ class NgtCommonDirective {
82
82
  this.injected = false;
83
83
  this.injectedValue = null;
84
84
  effect(() => {
85
- const value = this.linkedValue();
86
85
  if (this.shouldSkipRender())
87
86
  return;
87
+ const value = this.linkedValue();
88
88
  if (is.equ(value, this.injectedValue)) {
89
89
  // we have the same value as before, no need to update
90
90
  return;
@@ -614,6 +614,13 @@ function injectStore(options) {
614
614
  return inject(NGT_STORE, options);
615
615
  }
616
616
 
617
+ function resolveRef(ref) {
618
+ if (is.ref(ref)) {
619
+ return ref.nativeElement;
620
+ }
621
+ return ref;
622
+ }
623
+
617
624
  class NgtParent extends NgtCommonDirective {
618
625
  constructor() {
619
626
  super();
@@ -628,10 +635,7 @@ class NgtParent extends NgtCommonDirective {
628
635
  if (typeof rawParent === 'string') {
629
636
  return scene.getObjectByName(rawParent);
630
637
  }
631
- if ('nativeElement' in rawParent) {
632
- return rawParent.nativeElement;
633
- }
634
- return rawParent;
638
+ return resolveRef(rawParent);
635
639
  });
636
640
  this.linkedValue = linkedSignal(this._parent);
637
641
  this.shouldSkipRender = computed(() => !this._parent());
@@ -3008,32 +3012,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.1.4", ngImpor
3008
3012
  * `injectBeforeRender` invokes its callback on every frame. Hence, the notion of tracking
3009
3013
  * changes (i.e: signals) does not really matter since we're getting latest values of the things we need on every frame anyway.
3010
3014
  *
3011
- * If `priority` is dynamic, consumers should set up `injectBeforeRender` in
3012
- * an `effect` and track `priority` changes. Make use of `onCleanup` to clean up
3013
- * previous before render subscription
3015
+ * If `priority` is a Signal, `injectBeforeRender` will set up an Effect internally and returns the `EffectRef#destroy` instead.
3014
3016
  *
3015
3017
  * @example
3016
3018
  * ```ts
3017
- * const injector = inject(Injector);
3018
- *
3019
- * effect((onCleanup) => {
3020
- * const priority = this.priority(); // track priority
3021
- *
3022
- * const sub = injectBeforeRender(
3023
- * ({ gl, camera }) => {
3024
- * // before render logic
3025
- * },
3026
- * {
3027
- * priority,
3028
- * injector, // injector is needed since injectBeforeRender is invoked in effect body
3029
- * }
3030
- * });
3031
- *
3032
- * onCleanup(() => sub());
3033
- * });
3019
+ * const destroy = injectBeforeRender(
3020
+ * ({ gl, camera }) => {
3021
+ * // before render logic
3022
+ * },
3023
+ * {
3024
+ * priority: this.priority, // this.priority is a Signal<number>
3025
+ * }
3026
+ * )
3034
3027
  * ```
3035
3028
  */
3036
3029
  function injectBeforeRender(cb, { priority = 0, injector } = {}) {
3030
+ if (typeof priority === 'function') {
3031
+ const effectRef = assertInjector(injectBeforeRender, injector, () => {
3032
+ const store = injectStore();
3033
+ const ref = effect((onCleanup) => {
3034
+ const p = priority();
3035
+ const sub = store.snapshot.internal.subscribe(cb, p, store);
3036
+ onCleanup(() => sub());
3037
+ });
3038
+ inject(DestroyRef).onDestroy(() => void ref.destroy());
3039
+ return ref;
3040
+ });
3041
+ return effectRef.destroy.bind(effectRef);
3042
+ }
3037
3043
  return assertInjector(injectBeforeRender, injector, () => {
3038
3044
  const store = injectStore();
3039
3045
  const sub = store.snapshot.internal.subscribe(cb, priority, store);
@@ -3042,13 +3048,6 @@ function injectBeforeRender(cb, { priority = 0, injector } = {}) {
3042
3048
  });
3043
3049
  }
3044
3050
 
3045
- function resolveRef(ref) {
3046
- if (is.ref(ref)) {
3047
- return ref.nativeElement;
3048
- }
3049
- return ref;
3050
- }
3051
-
3052
3051
  /**
3053
3052
  * As host directive:
3054
3053
  * - outputs: [