Commit graph

18 commits

Author SHA1 Message Date
Kristiyan Kostadinov
39a50f9a8d fix(core): ensure all initializer functions run in an injection context (#54761)
Ensures that all of the functions intended to be run in initializers are in an injection context. This is a stop-gap until we have a compiler diagnostic for it.

PR Close #54761
2024-03-12 09:08:08 -07:00
Matthieu Riegler
7243c704cf fix(core): return a readonly signal on asReadonly. (#54706)
Previous `asReadonly()` returned the signal value and not the signal itself.

Fixes #54704

PR Close #54706
2024-03-06 14:41:12 +01:00
Paul Gschwendtner
30355f6719 refactor(core): model() implements OutputRef (#54650)
A model signal is technically an output, at runtime and conceptually.

This commit re-uses the shared output ref logic and ensures the
interfaces match.

PR Close #54650
2024-03-06 12:34:38 +01:00
Kristiyan Kostadinov
be4620c8d0 test(core): add type tests for ɵunwrapWritableSignal (#54387)
Getting the typing for `ɵunwrapWritableSignal` just right was tricky so these changes add some tests to ensure that we don't regress.

Also reworks the type tester a bit to make it easier to find where to add new test files.

PR Close #54387
2024-02-12 11:01:52 -08:00
Kristiyan Kostadinov
4a7ca50328 refactor(core): avoid wrapper around subscribe return value (#54387)
Reworks `ModelSignal.subscribe` so it doesn't have to wrap its value to look like a subscription.

PR Close #54387
2024-02-12 11:01:52 -08:00
cexbrayat
8dea3b5888 test: tidy up signal signal input/query/model signature tests (#54334)
This updates some tests to use the public imports from `@angular/core` now that they are available,
and cleans up useless imports and inaccurate names.

PR Close #54334
2024-02-08 16:49:15 +00:00
Kristiyan Kostadinov
551c5791f8 refactor(core): address PR feedback (#54252)
Addresses the feedback from #54252.

PR Close #54252
2024-02-07 16:36:12 +00:00
Kristiyan Kostadinov
3e0a20d8fe refactor(core): add model implementation (#54252)
Adds the implementation of the `model` primitive that represents a two-way binding signal-based binding.

PR Close #54252
2024-02-07 16:36:01 +00:00
Kristiyan Kostadinov
50b22a4260 refactor(core): move input signals into own directory (#54200)
Moves the signal input code into its own directory to avoid too many files in the `authoring` root once model inputs are introduced.

PR Close #54200
2024-02-01 15:58:50 +00:00
Paul Gschwendtner
b78042f3a5 refactor(core): separate InputSignal and InputSignalWithTransform (#54053)
This commit separates `InputSignal` for input signals with transforms.
The reason being that most of the time, signal inputs are not using
transforms and the generics are rather confusing.

Especially for users with inferred types displayed in their IDEs, the
input signal types are seemingly complex, even if no transform is used.

For this reason, we are introducing a new type called
`InputSignalWithTransform`. This type will be used for inputs with
transforms, while non-transform inputs just use `InputSignal`.

A notable fact is that `InputSignal` extends `InputSignalWithTransform`,
with the "identity transform". i.e. there is no transform. This allows
us to share the code for input signals. In practice, we don't expect
users to pass around `InputSignal`'s anyway.

PR Close #54053
2024-01-26 19:10:56 +00:00
Kristiyan Kostadinov
c637dfa092 refactor(core): signals toString improvements (#54079)
Follow-up to #54002 that:
* Remove the `toString` implementation from the `primitives`.
* Guards the `toString` with `ngDevMode` and prints out the value.

PR Close #54079
2024-01-25 20:45:02 +00:00
Kristiyan Kostadinov
656bc282e3 fix(core): add toString implementation to signals (#54002)
Since signals are function, currently stringifying them reveals the implementation of the function. This can lead to confusion since it contains internal implementation details. These changes add static `toString` function to address the issue.

**Note:** it's tempting to have `toString` output the actual value of the signal, but that would encourage users not to call the function which will be problematic in the long run. That's why these changes are using a static string instead.

PR Close #54002
2024-01-25 17:11:30 +00:00
Dylan Hunn
4fd78a99d2 revert: no longer depend on forwardRef changes (#53961)
Revert only the part of the signal queries PRs that depends on the forward ref changes, which were reverted.

PR Close #53961
2024-01-17 13:56:07 -08:00
Pawel Kozlowski
616df433c9 test(core): support type tests for different authoring functions (#53829)
The new type testing infrastructure was introduced for the input-as-signals
authoring functions. This commit modifies this infrastructure to make it more
generic and support queries-as-signals.

PR Close #53829
2024-01-17 09:15:14 -08:00
Pawel Kozlowski
e1ac52a0b4 refactor(core): introduce query-as-signal authoring functions (#53829)
This commit adds signatures of the quer-as-signal authoring functions
and their respective type tests.

PR Close #53829
2024-01-17 09:15:14 -08:00
Paul Gschwendtner
863be4b698 feat(core): expose new input API for signal-based inputs (#53872)
Enables signal inputs for existing Zone based components.
This is a next step we are taking to bring signal inputs earlier to the Angular community.

The goal is to enable early access for the ecosystem to signal inputs, while we are continuing
development of full signal components as outlined in the RFC. This will allow the ecosystem
to start integrating signals more deeply, prepare for future migrations, and improves code quality
and DX for existing components (especially for OnPush).

Based on our work on full signal components, we've gathered more information and learned
new things. We've improved the API by introducing a way to intuitively declare required inputs,
as well as improved the API around initial values. We even support non-primitive initial values
as the first argument to the `input` function now.

```ts
@Directive({..})
export class MyDir {
  firstName = input<string>();            // string|undefined
  lastName = input.required<string>();    // string
  age = input(0);                         // number
```

PR Close #53872
2024-01-10 12:33:31 -08:00
Paul Gschwendtner
977884a0c8 test(core): add runtime tests for input signal (#53808)
This commit adds some runtime unit tests to ensure that input
signal is behaving properly at runtime.

PR Close #53808
2024-01-10 12:21:05 +00:00
Paul Gschwendtner
4e2f0b7f0d test(core): add type signature test for signal input API (#53571)
Adds tests that allow us to ensure that the `input` API works as
expected and that resulting return types match our expectations- without
silently regressing in the future, or missing potential edge-cases.

Testing signatures is hard because of covariance and contravariance,
especially when it comes to the different semantics of `ReadT` and
`WriteT` of input signals. We enable reliable testing by validating the
`d.ts` of the "fake directive class". This ensures clear results,
compared to relying on e.g. type assertions that might
accidentally/silently pass due to covariance/contravariance or
biavariance in the type system.

PR Close #53571
2024-01-04 12:07:13 -08:00