From d49aec75df76af7b6c2bc4e48cf89893c2dbf835 Mon Sep 17 00:00:00 2001 From: Paul Gschwendtner Date: Thu, 1 Jun 2023 13:36:34 +0000 Subject: [PATCH] WIP: implementation of `input` function signature --- packages/core/src/signals-wip/index.ts | 25 +++++++++++++++--- packages/core/src/signals-wip/test/index.ts | 29 +++++++++++++++++---- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/packages/core/src/signals-wip/index.ts b/packages/core/src/signals-wip/index.ts index 6198bef4abd..d62c87b42ee 100644 --- a/packages/core/src/signals-wip/index.ts +++ b/packages/core/src/signals-wip/index.ts @@ -6,7 +6,26 @@ export interface InputOptions { // TODO: transform } -// WIP starting point -export function input(defaultVal: T, opts?: InputOptions): Signal { - return signal(defaultVal); +export interface InputOptionsWithInitialValue extends InputOptions { + initialValue?: T; +} + +// it transforms our specific types into primitive origins +type toPrimitive = + T extends string ? string : T extends number ? number : T extends boolean ? boolean : T; + +type primitiveValue = string|number|boolean|BigInt|undefined|null|Symbol + +export function input(): Signal; +export function input(opts: InputOptionsWithInitialValue): Signal; +export function input( + defaultVal: T, opts?: InputOptions): Signal>; + +export function input, Y>( + defaultValOrOpts?: T, opts?: InputOptions): Signal { + // TODO(signals): implement + return signal( + typeof defaultValOrOpts === 'object' ? + (defaultValOrOpts as InputOptionsWithInitialValue).initialValue : + defaultValOrOpts) as unknown as Signal; } diff --git a/packages/core/src/signals-wip/test/index.ts b/packages/core/src/signals-wip/test/index.ts index f3b29549cc7..526a466967c 100644 --- a/packages/core/src/signals-wip/test/index.ts +++ b/packages/core/src/signals-wip/test/index.ts @@ -1,19 +1,38 @@ -import {Component, input} from '@angular/core'; +import {Component, input, Input} from '@angular/core'; import {bootstrapApplication} from '@angular/platform-browser'; @Component({ selector: 'greet', standalone: true, signals: true, - template: `{{ nameInput() }}`, + template: `{{ counter() }}`, }) -class Greet { - nameInput = input('Jeff'); +export class Greet { + counter = input(0); + bla = input(); // TODO: should be a diagnostic. no type & no value + bla2 = input() + bla3 = input({initialValue: 3, required: true}); + bla4 = input(3, {required: true, alias: 'bla4Public'}) + gen = input({required: true}); + gen2 = input(); + + works(): T { + return this.gen(); + } + + // TODO: should break, but still supported early prototype. + @Input() oldInput: string|undefined; } @Component({ standalone: true, - template: `Hello `, + template: ` + Hello + + + `, imports: [Greet], }) export class MyApp {