Skip to content

Commit a4e76bb

Browse files
committed
refactor: move to signals
1 parent 5c0e3e7 commit a4e76bb

File tree

85 files changed

+1700
-628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1700
-628
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
with:
1717
token: ${{ secrets.TAIGA_FAMILY_BOT_PAT }}
1818
branch: gh-pages
19-
folder: dist/demo
19+
folder: dist/demo/browser
2020
silent: false
2121
clean: true
2222

apps/demo/project.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"path": "apps/demo/webpack.config.ts"
1515
},
1616
"aot": true,
17-
"outputPath": "dist/demo",
17+
"outputPath": "dist/demo/browser",
1818
"index": "apps/demo/src/index.html",
1919
"main": "apps/demo/src/main.ts",
2020
"polyfills": "apps/demo/src/polyfills.ts",
@@ -110,7 +110,7 @@
110110
"echo 'Read more: https://angular.io/guide/deployment#deploy-to-github-pages'",
111111
"echo ------",
112112
"nx build demo -c github",
113-
"cp dist/demo/index.html dist/demo/404.html",
113+
"cp dist/demo/browser/index.html dist/demo/browser/404.html",
114114
"nx run demo:prerender -c github"
115115
]
116116
}

apps/demo/src/app/pages/audio/audio-page.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ <h2>Source</h2>
7373
[fftSize]="fftSize"
7474
(timeByte$)="onTimeDomain($event)"
7575
>
76-
<ng-container [waOutput]="chain || fallback" />
76+
<ng-container [waOutput]="chain() || fallback" />
7777
</ng-container>
7878
</button>
7979
}
@@ -90,7 +90,7 @@ <h2>Source</h2>
9090
[fftSize]="fftSize"
9191
(timeByte$)="onTimeDomain($event)"
9292
>
93-
<ng-container [waOutput]="chain || fallback" />
93+
<ng-container [waOutput]="chain() || fallback" />
9494
</ng-container>
9595
</audio>
9696
}
@@ -112,7 +112,7 @@ <h2>Source</h2>
112112
[fftSize]="fftSize"
113113
(timeByte$)="onTimeDomain($event)"
114114
>
115-
<ng-container [waOutput]="chain || fallback" />
115+
<ng-container [waOutput]="chain() || fallback" />
116116
</ng-container>
117117
</button>
118118
}

apps/demo/src/app/pages/audio/audio-page.component.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {CommonModule} from '@angular/common';
2-
import {ChangeDetectionStrategy, Component, inject, ViewChild} from '@angular/core';
2+
import {ChangeDetectionStrategy, Component, inject, viewChild} from '@angular/core';
33
import {FormsModule} from '@angular/forms';
44
import {AUDIO_CONTEXT, WaWebAudio} from '@ng-web-apis/audio';
55
import {CanvasModule} from '@ng-web-apis/canvas';
@@ -30,8 +30,7 @@ import {TuiSelectModule, TuiTextfieldControllerModule} from '@taiga-ui/legacy';
3030
export default class AudioPage {
3131
private readonly context = inject<AudioContext>(AUDIO_CONTEXT);
3232

33-
@ViewChild('chain')
34-
protected readonly chain?: AudioNode;
33+
protected readonly chain = viewChild<AudioNode>('chain');
3534

3635
protected buffers = [Date.now()];
3736

eslint.config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export default [
1616
{
1717
files: ['**/*.ts'],
1818
rules: {
19-
'@angular-eslint/prefer-signals': 'off',
20-
'@angular-eslint/prefer-output-readonly': 'off',
2119
'@angular-eslint/no-attribute-decorator': 'off',
2220
'@typescript-eslint/prefer-promise-reject-errors': 'off',
2321
},

libs/audio/src/decorators/audio-param.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {effect, isSignal, type Signal} from '@angular/core';
2+
13
import {type AudioNodeWithParams} from '../types/audio-node-with-params';
24
import {
35
type AudioParamDecorator,
@@ -14,24 +16,40 @@ export function audioParam<K extends string>(
1416
const decorator: AudioParamDecorator<K> = (target, propertyKey) => {
1517
Object.defineProperty(target, propertyKey, {
1618
configurable: true,
17-
set(this: AudioNodeWithParams<K> | AudioWorkletNode, value: AudioParamInput) {
19+
set: function (
20+
this: AudioNodeWithParams<K> | AudioWorkletNode,
21+
value: AudioParamInput | Signal<AudioParamInput>,
22+
) {
1823
value = typeof value === 'string' ? Number.parseFloat(value) : value;
1924

20-
const audioParam =
21-
this instanceof AudioWorkletNode
22-
? (this.parameters as Map<string, AudioParam | undefined>).get(
23-
propertyKey,
24-
)
25-
: this[param as K];
25+
const processParam = (current: AudioParamInput): void => {
26+
const audioParam =
27+
this instanceof AudioWorkletNode
28+
? (
29+
this.parameters as Map<string, AudioParam | undefined>
30+
).get(param)
31+
: (this[param as K] as AudioParam);
32+
33+
if (audioParam instanceof AudioParam) {
34+
const num =
35+
typeof current === 'string'
36+
? Number.parseFloat(current)
37+
: current;
38+
39+
processAudioParam(audioParam, num, this.context.currentTime);
40+
} else {
41+
// Fallback for older browsers
42+
Object.defineProperty(target, propertyKey, {
43+
value,
44+
configurable: true,
45+
});
46+
}
47+
};
2648

27-
if (audioParam instanceof AudioParam) {
28-
processAudioParam(audioParam, value, this.context.currentTime);
49+
if (isSignal(value)) {
50+
effect(() => processParam(value()));
2951
} else {
30-
// Fallback for older browsers
31-
Object.defineProperty(target, propertyKey, {
32-
value,
33-
configurable: true,
34-
});
52+
processParam(value);
3553
}
3654
},
3755
});

libs/audio/src/directives/destination.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ import {connect} from '../utils/connect';
2222
exportAs: 'AudioNode',
2323
})
2424
export class WebAudioDestination extends AnalyserNode implements OnDestroy {
25+
// NOTE:
26+
// public quiet = output();
27+
// thrown TypeError: Cannot read properties of undefined (reading 'Symbol(SIGNAL)')
2528
@Output()
29+
// eslint-disable-next-line @angular-eslint/prefer-output-readonly
2630
public quiet!: Observable<unknown>;
2731

2832
constructor() {

libs/audio/src/directives/listener.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,83 @@ import {fallbackAudioParam} from '../utils/fallback-audio-param';
1111
selector: '[waAudioContext],[waOfflineAudioContext][length][sampleRate]',
1212
})
1313
export class WebAudioListener extends GainNode implements OnChanges {
14+
// thrown TS2401
15+
// A 'super' call must be a root-level statement within
16+
// a constructor of a derived class that contains initialized
17+
// properties, parameter properties, or private identifiers.
18+
// eslint-disable-next-line @angular-eslint/prefer-signals
1419
@Input('forwardX')
1520
@audioParam('forwardX')
1621
public forwardXParam?: AudioParamInput;
1722

23+
// thrown TS2401
24+
// A 'super' call must be a root-level statement within
25+
// a constructor of a derived class that contains initialized
26+
// properties, parameter properties, or private identifiers.
27+
// eslint-disable-next-line @angular-eslint/prefer-signals
1828
@Input('forwardY')
1929
@audioParam('forwardY')
2030
public forwardYParam?: AudioParamInput;
2131

32+
// thrown TS2401
33+
// A 'super' call must be a root-level statement within
34+
// a constructor of a derived class that contains initialized
35+
// properties, parameter properties, or private identifiers.
36+
// eslint-disable-next-line @angular-eslint/prefer-signals
2237
@Input('forwardZ')
2338
@audioParam('forwardZ')
2439
public forwardZParam?: AudioParamInput;
2540

41+
// thrown TS2401
42+
// A 'super' call must be a root-level statement within
43+
// a constructor of a derived class that contains initialized
44+
// properties, parameter properties, or private identifiers.
45+
// eslint-disable-next-line @angular-eslint/prefer-signals
2646
@Input('positionX')
2747
@audioParam('positionX')
2848
public positionXParam?: AudioParamInput;
2949

50+
// thrown TS2401
51+
// A 'super' call must be a root-level statement within
52+
// a constructor of a derived class that contains initialized
53+
// properties, parameter properties, or private identifiers.
54+
// eslint-disable-next-line @angular-eslint/prefer-signals
3055
@Input('positionY')
3156
@audioParam('positionY')
3257
public positionYParam?: AudioParamInput;
3358

59+
// thrown TS2401
60+
// A 'super' call must be a root-level statement within
61+
// a constructor of a derived class that contains initialized
62+
// properties, parameter properties, or private identifiers.
63+
// eslint-disable-next-line @angular-eslint/prefer-signals
3464
@Input('positionZ')
3565
@audioParam('positionZ')
3666
public positionZParam?: AudioParamInput;
3767

68+
// thrown TS2401
69+
// A 'super' call must be a root-level statement within
70+
// a constructor of a derived class that contains initialized
71+
// properties, parameter properties, or private identifiers.
72+
// eslint-disable-next-line @angular-eslint/prefer-signals
3873
@Input('upX')
3974
@audioParam('upX')
4075
public upXParam?: AudioParamInput;
4176

77+
// thrown TS2401
78+
// A 'super' call must be a root-level statement within
79+
// a constructor of a derived class that contains initialized
80+
// properties, parameter properties, or private identifiers.
81+
// eslint-disable-next-line @angular-eslint/prefer-signals
4282
@Input('upY')
4383
@audioParam('upY')
4484
public upYParam?: AudioParamInput;
4585

86+
// thrown TS2401
87+
// A 'super' call must be a root-level statement within
88+
// a constructor of a derived class that contains initialized
89+
// properties, parameter properties, or private identifiers.
90+
// eslint-disable-next-line @angular-eslint/prefer-signals
4691
@Input('upZ')
4792
@audioParam('upZ')
4893
public upZParam?: AudioParamInput;

libs/audio/src/directives/output.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export class WebAudioOutput extends GainNode implements OnDestroy {
3232
connect(node, that);
3333
}
3434

35+
// NOTE:
36+
// public readonly waOutput = input();
37+
// thrown TypeError: Cannot read properties of undefined (reading 'Symbol(SIGNAL)')
38+
// eslint-disable-next-line @angular-eslint/prefer-signals
3539
@Input()
3640
public set waOutput(destination: AudioNode | AudioParam | undefined) {
3741
this.disconnect();

libs/audio/src/nodes/analyser.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,36 @@ import {parse} from '../utils/parse';
2424
exportAs: 'AudioNode',
2525
})
2626
export class WebAudioAnalyser extends AnalyserNode implements OnDestroy {
27-
// '!' because it is actually set in constructor
27+
// thrown TS2401
28+
// A 'super' call must be a root-level statement within
29+
// a constructor of a derived class that contains initialized
30+
// properties, parameter properties, or private identifiers.
2831
@Output()
32+
// eslint-disable-next-line @angular-eslint/prefer-output-readonly
2933
public frequencyByte$!: Observable<Uint8Array>;
3034

35+
// thrown TS2401
36+
// A 'super' call must be a root-level statement within
37+
// a constructor of a derived class that contains initialized
38+
// properties, parameter properties, or private identifiers.
3139
@Output()
40+
// eslint-disable-next-line @angular-eslint/prefer-output-readonly
3241
public frequencyFloat$!: Observable<Float32Array>;
3342

43+
// thrown TS2401
44+
// A 'super' call must be a root-level statement within
45+
// a constructor of a derived class that contains initialized
46+
// properties, parameter properties, or private identifiers.
3447
@Output()
48+
// eslint-disable-next-line @angular-eslint/prefer-output-readonly
3549
public timeByte$!: Observable<Uint8Array>;
3650

51+
// thrown TS2401
52+
// A 'super' call must be a root-level statement within
53+
// a constructor of a derived class that contains initialized
54+
// properties, parameter properties, or private identifiers.
3755
@Output()
56+
// eslint-disable-next-line @angular-eslint/prefer-output-readonly
3857
public timeFloat$!: Observable<Float32Array>;
3958

4059
constructor(

0 commit comments

Comments
 (0)