Skip to content

Commit 63084b6

Browse files
pkozlowski-opensourcedevversion
authored andcommitted
feat(core): add runtime support for outputs in signal components
Runtime implementation is very simple - it adds the output function that acts as an alias to the existing EventEmitter class constructor.
1 parent 1200ae9 commit 63084b6

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

goldens/public-api/core/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,9 @@ export interface Output {
11941194
// @public (undocumented)
11951195
export const Output: OutputDecorator;
11961196

1197+
// @public (undocumented)
1198+
export function output<T>(isAsync?: boolean): EventEmitter<T>;
1199+
11971200
// @public
11981201
export interface OutputDecorator {
11991202
(alias?: string): any;

packages/core/src/core_reactivity_export_internal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ export {input} from './render3/reactivity/input';
4040
export {InputSignal, ɵɵGetInputSignalWriteType} from './render3/reactivity/input_signal';
4141
export {ModelSignal} from './render3/reactivity/model_signal';
4242
export {contentChild, contentChildren, viewChild, viewChildren} from './render3/reactivity/queries';
43+
export {output} from './render3/reactivity/output';
4344
// clang-format on
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {EventEmitter} from '../../event_emitter';
10+
11+
export function output<T>(isAsync?: boolean): EventEmitter<T> {
12+
return new EventEmitter(isAsync);
13+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Component, Output, output, signal} from '@angular/core';
10+
import {TestBed} from '@angular/core/testing';
11+
12+
describe('outputs', () => {
13+
xit('should subscribe to signal directive outputs', () => {
14+
@Component({
15+
selector: 'with-output-cmp',
16+
standalone: true,
17+
signals: true,
18+
template: `<button (click)="increment.emit()"></button>`,
19+
})
20+
class WithOutputCmp {
21+
counter = signal(0);
22+
@Output() increment = output<void>();
23+
}
24+
25+
@Component({
26+
signals: true,
27+
standalone: true,
28+
imports: [WithOutputCmp],
29+
template: `<with-output-cmp (increment)="bumpUp()" />{{inc()}}`,
30+
})
31+
class App {
32+
inc = signal(0);
33+
onIncrement() {
34+
this.inc.update(c => c + 1);
35+
}
36+
}
37+
38+
const fixture = TestBed.createComponent(App);
39+
fixture.detectChanges();
40+
expect(fixture.nativeElement.textContent).toBe('0');
41+
});
42+
});

0 commit comments

Comments
 (0)