angular/packages/core/test/bundling
Kristiyan Kostadinov 68017d4e75 feat(core): add ability to transform input values (#50420)
According to the HTML specification most attributes are defined as strings, however some can be interpreted as different types like booleans or numbers. [In the HTML standard](https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#boolean-attributes), boolean attributes are considered `true` if they are present on a DOM node and `false` if they are omitted. Common examples of boolean attributes are `disabled` on interactive elements like `<button>` or `checked` on `<input type="checkbox">`. Another example of an attribute that is defined as a string, but interpreted as a different type is the `value` attribute of `<input type="number">` which logs a warning and ignores the value if it can't be parsed as a number.

Historically, authoring Angular inputs that match the native behavior in a type-safe way has been difficult for developers, because Angular interprets all static attributes as strings. While some recent TypeScript versions made this easier by allowing setters and getters to have different types, supporting this pattern still requires a lot of boilerplate and additional properties to be declared. For example, currently developers have to write something like this to have a `disabled` input that behaves like the native one:

```typescript
import {Directive, Input} from '@angular/core';

@Directive({selector: 'mat-checkbox'})
export class MatCheckbox {
  @Input()
  get disabled() {
    return this._disabled;
  }
  set disabled(value: any) {
    this._disabled = typeof value === 'boolean' ? value : (value != null && value !== 'false');
  }
  private _disabled = false;
}
```

This feature aims to address the issue by introducing a `transform` property on inputs. If an input has a `transform` function, any values set through the template will be passed through the function before being assigned to the directive instance. The example from above can be rewritten to the following:

```typescript
import {Directive, Input, booleanAttribute} from '@angular/core';

@Directive({selector: 'mat-checkbox'})
export class MatCheckbox {
  @Input({transform: booleanAttribute}) disabled: boolean = false;
}
```

These changes also add the `booleanAttribute` and `numberAttribute` utilities to `@angular/core` since they're common enough to be useful for most projects.

Fixes #8968.
Fixes #14761.

PR Close #50420
2023-05-30 13:01:13 -07:00
..
animation_world build: remove remaining usages of deprecated ts_devserver (#48521) 2022-12-19 19:50:44 +00:00
animations fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425) 2023-05-30 12:58:22 -07:00
animations-standalone fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425) 2023-05-30 12:58:22 -07:00
core_all build: update dev-infra packages and account for build-tooling split from ng-dev (#46976) 2022-08-02 09:37:37 -07:00
cyclic_import fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425) 2023-05-30 12:58:22 -07:00
forms_reactive fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425) 2023-05-30 12:58:22 -07:00
forms_template_driven feat(core): add ability to transform input values (#50420) 2023-05-30 13:01:13 -07:00
hello_world fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425) 2023-05-30 12:58:22 -07:00
hello_world_i18n test(core): convert remaining bundling tests to not use renderComponent (#46559) 2022-06-28 21:37:45 -07:00
hydration fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425) 2023-05-30 12:58:22 -07:00
image-directive refactor(common): Reduce the precision to 2 digits in the ngOptimizedImage distortion warning message (#50276) 2023-05-16 09:23:15 -07:00
injection build: lock file maintenance (#50227) 2023-05-10 11:32:43 -07:00
router feat(core): add ability to transform input values (#50420) 2023-05-30 13:01:13 -07:00
standalone_bootstrap fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425) 2023-05-30 12:58:22 -07:00
todo fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425) 2023-05-30 12:58:22 -07:00
todo_i18n build: remove remaining usages of deprecated ts_devserver (#48521) 2022-12-19 19:50:44 +00:00
util build: update license headers to reference Google LLC (#37205) 2020-05-26 14:26:58 -04:00
README.md fix(core): remove individual commands for updating gold files (#45198) 2022-03-01 19:16:53 +00:00

Bundle

js_expected_symbol_test

This folder contains tests which assert that most of the code is tree shaken away. This is asserted by keeping gold files of all symbols which are expected to be retained. When doing renaming it is often necessary to update the gold files; to do so use these scripts:

yarn run symbol-extractor:check
yarn run symbol-extractor:update