Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b21f71d

Browse files
authored
feat: drop mirror signal in favor of linked signal (#493)
1 parent c5898c0 commit b21f71d

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

projects/angular-split/src/lib/split-area/split-area.component.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import {
88
inject,
99
input,
1010
isDevMode,
11+
linkedSignal,
1112
} from '@angular/core'
1213
import { SPLIT_AREA_CONTRACT, SplitComponent } from '../split/split.component'
13-
import { createClassesString, mirrorSignal } from '../utils'
14+
import { createClassesString } from '../utils'
1415
import { SplitAreaSize, areaSizeTransform, boundaryAreaSizeTransform } from '../models'
1516

1617
@Component({
@@ -39,19 +40,15 @@ export class SplitAreaComponent {
3940
/**
4041
* @internal
4142
*/
42-
readonly _internalSize = mirrorSignal(
43-
// As size is an input and we can change the size without the outside
44-
// listening to the change we need an intermediate writeable signal
45-
computed((): SplitAreaSize => {
46-
if (!this.visible()) {
47-
return 0
48-
}
43+
readonly _internalSize = linkedSignal((): SplitAreaSize => {
44+
if (!this.visible()) {
45+
return 0
46+
}
4947

50-
const visibleIndex = this.split._visibleAreas().findIndex((area) => area === this)
48+
const visibleIndex = this.split._visibleAreas().findIndex((area) => area === this)
5149

52-
return this.split._alignedVisibleAreasSizes()[visibleIndex]
53-
}),
54-
)
50+
return this.split._alignedVisibleAreasSizes()[visibleIndex]
51+
})
5552
/**
5653
* @internal
5754
*/

projects/angular-split/src/lib/utils.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NgZone, Signal, computed, inject, numberAttribute, signal, untracked } from '@angular/core'
1+
import { NgZone, inject, numberAttribute } from '@angular/core'
22
import { Observable, filter, fromEvent, merge } from 'rxjs'
33

44
export interface ClientPoint {
@@ -106,25 +106,6 @@ export function createClassesString(classesRecord: Record<string, boolean>) {
106106
.join(' ')
107107
}
108108

109-
export interface MirrorSignal<T> {
110-
(): T
111-
set(value: T): void
112-
reset(): void
113-
}
114-
115-
/**
116-
* Creates a semi signal which allows writes but is based on an existing signal
117-
* Whenever the original signal changes the mirror signal gets aligned
118-
* overriding the current value inside.
119-
*/
120-
export function mirrorSignal<T>(outer: Signal<T>): MirrorSignal<T> {
121-
const inner = computed(() => signal(outer()))
122-
const mirror: MirrorSignal<T> = () => inner()()
123-
mirror.set = (value: T) => untracked(inner).set(value)
124-
mirror.reset = () => untracked(() => inner().set(outer()))
125-
return mirror
126-
}
127-
128109
export function leaveNgZone<T>() {
129110
return (source: Observable<T>) =>
130111
new Observable<T>((observer) => inject(NgZone).runOutsideAngular(() => source.subscribe(observer)))

0 commit comments

Comments
 (0)