1
+ import { DOCUMENT , NgStyle , NgTemplateOutlet } from '@angular/common'
1
2
import {
2
3
ChangeDetectionStrategy ,
3
4
Component ,
4
5
ElementRef ,
5
6
HostBinding ,
6
7
InjectionToken ,
7
8
NgZone ,
8
- Renderer2 ,
9
+ afterRenderEffect ,
9
10
booleanAttribute ,
10
11
computed ,
11
12
contentChild ,
12
13
contentChildren ,
13
- effect ,
14
14
inject ,
15
15
input ,
16
16
isDevMode ,
17
17
output ,
18
18
signal ,
19
19
} from '@angular/core'
20
20
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'
21
- import type { SplitAreaComponent } from '../split-area/split-area.component'
22
21
import {
23
22
Subject ,
24
23
filter ,
@@ -33,26 +32,26 @@ import {
33
32
takeUntil ,
34
33
tap ,
35
34
} from 'rxjs'
35
+ import { ANGULAR_SPLIT_DEFAULT_OPTIONS } from '../angular-split-config.token'
36
+ import { SplitGutterDynamicInjectorDirective } from '../gutter/split-gutter-dynamic-injector.directive'
37
+ import { SplitGutterDirective } from '../gutter/split-gutter.directive'
38
+ import { SplitAreaSize , SplitGutterInteractionEvent } from '../models'
39
+ import type { SplitAreaComponent } from '../split-area/split-area.component'
40
+ import { SplitCustomEventsBehaviorDirective } from '../split-custom-events-behavior.directive'
36
41
import {
37
42
ClientPoint ,
43
+ assertUnreachable ,
38
44
createClassesString ,
39
- gutterEventsEqualWithDelta ,
40
45
fromMouseMoveEvent ,
41
46
fromMouseUpEvent ,
42
47
getPointFromEvent ,
48
+ gutterEventsEqualWithDelta ,
43
49
leaveNgZone ,
44
50
numberAttributeWithFallback ,
45
51
sum ,
46
52
toRecord ,
47
- assertUnreachable ,
48
53
} from '../utils'
49
- import { DOCUMENT , NgStyle , NgTemplateOutlet } from '@angular/common'
50
- import { SplitGutterInteractionEvent , SplitAreaSize } from '../models'
51
- import { SplitCustomEventsBehaviorDirective } from '../split-custom-events-behavior.directive'
52
54
import { areAreasValid } from '../validations'
53
- import { SplitGutterDirective } from '../gutter/split-gutter.directive'
54
- import { SplitGutterDynamicInjectorDirective } from '../gutter/split-gutter-dynamic-injector.directive'
55
- import { ANGULAR_SPLIT_DEFAULT_OPTIONS } from '../angular-split-config.token'
56
55
57
56
interface MouseDownContext {
58
57
mouseDownEvent : MouseEvent | TouchEvent
@@ -88,7 +87,6 @@ export const SPLIT_AREA_CONTRACT = new InjectionToken<SplitAreaComponent>('Split
88
87
} )
89
88
export class SplitComponent {
90
89
private readonly document = inject ( DOCUMENT )
91
- private readonly renderer = inject ( Renderer2 )
92
90
private readonly elementRef = inject < ElementRef < HTMLElement > > ( ElementRef )
93
91
private readonly ngZone = inject ( NgZone )
94
92
private readonly defaultOptions = inject ( ANGULAR_SPLIT_DEFAULT_OPTIONS )
@@ -164,22 +162,28 @@ export class SplitComponent {
164
162
constructor ( ) {
165
163
if ( isDevMode ( ) ) {
166
164
// Logs warnings to console when the provided areas sizes are invalid
167
- effect ( ( ) => {
168
- // Special mode when no size input was declared which is a valid mode
169
- if ( this . unit ( ) === 'percent' && this . _visibleAreas ( ) . every ( ( area ) => area . size ( ) === 'auto' ) ) {
170
- return
171
- }
165
+ afterRenderEffect ( {
166
+ // we use the afterRender read phase here,
167
+ // because we want to run this after all processing is done.
168
+ // and we are not updating anything in the DOM
169
+ read : ( ) => {
170
+ // Special mode when no size input was declared which is a valid mode
171
+ if ( this . unit ( ) === 'percent' && this . _visibleAreas ( ) . every ( ( area ) => area . size ( ) === 'auto' ) ) {
172
+ return
173
+ }
172
174
173
- areAreasValid ( this . _visibleAreas ( ) , this . unit ( ) , true )
175
+ areAreasValid ( this . _visibleAreas ( ) , this . unit ( ) , true )
176
+ } ,
174
177
} )
175
178
}
176
179
177
- // Responsible for updating grid template style. Must be this way and not based on HostBinding
178
- // as change detection for host binding is bound to the parent component and this style
179
- // is updated on every mouse move. Doing it this way will prevent change detection cycles in parent.
180
- effect ( ( ) => {
181
- const gridTemplateColumnsStyle = this . gridTemplateColumnsStyle ( )
182
- this . renderer . setStyle ( this . elementRef . nativeElement , 'grid-template' , gridTemplateColumnsStyle )
180
+ // we are running this after Angular has completed its CD loop
181
+ // as we are updating the style of the host, and we don't want to re-trigger the CD loop
182
+ // doing this in the host of the component would retrigger the CD too many times
183
+ afterRenderEffect ( {
184
+ write : ( ) => {
185
+ this . elementRef . nativeElement . style . gridTemplate = this . gridTemplateColumnsStyle ( )
186
+ } ,
183
187
} )
184
188
185
189
this . gutterMouseDownSubject
0 commit comments