Skip to content

Commit fee6f0c

Browse files
committed
feat(forms): renamed from cva and implement
1 parent 0b2d761 commit fee6f0c

15 files changed

Lines changed: 94 additions & 35 deletions

File tree

projects/angularity/cva/README.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

projects/angularity/cva/src/public-api.ts

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Forms
2+
3+
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 17.2.0.
4+
5+
## Code scaffolding
6+
7+
Run `ng generate component component-name --project forms` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project forms`.
8+
9+
> Note: Don't forget to add `--project forms` or else it will be added to the default project in your `angular.json` file.
10+
11+
## Build
12+
13+
Run `ng build forms` to build the project. The build artifacts will be stored in the `dist/` directory.
14+
15+
## Publishing
16+
17+
After building your library with `ng build forms`, go to the dist folder `cd dist/forms` and run `npm publish`.
18+
19+
## Running unit tests
20+
21+
Run `ng test forms` to execute the unit tests via [Karma](https://karma-runner.github.io).
22+
23+
## Further help
24+
25+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3-
"dest": "../../../dist/angularity/cva",
3+
"dest": "../../../dist/angularity/forms",
44
"lib": {
55
"entryFile": "src/public-api.ts"
66
}
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
{
2-
"name": "@angularity/cva",
2+
"name": "@angularity/forms",
33
"version": "0.1.0-2",
44
"peerDependencies": {
55
"@angular/common": "^17.2.0",
6-
"@angular/core": "^17.2.0"
6+
"@angular/core": "^17.2.0",
7+
"@angular/forms": "^17.2.0",
8+
"@angularity/core": "*",
9+
"rxjs": "~7.8.0"
710
},
811
"dependencies": {
912
"tslib": "^2.3.0"
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{
2-
"name": "@angularity/cva",
2+
"name": "@angularity/forms",
33
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
44
"projectType": "library",
5-
"sourceRoot": "projects/angularity/cva/src",
5+
"sourceRoot": "projects/angularity/forms/src",
66
"prefix": "lib",
77
"targets": {
88
"build": {
99
"executor": "@angular-devkit/build-angular:ng-packagr",
1010
"options": {
11-
"project": "projects/angularity/cva/ng-package.json"
11+
"project": "projects/angularity/forms/ng-package.json"
1212
},
1313
"configurations": {
1414
"production": {
15-
"tsConfig": "projects/angularity/cva/tsconfig.lib.prod.json"
15+
"tsConfig": "projects/angularity/forms/tsconfig.lib.prod.json"
1616
},
1717
"development": {
18-
"tsConfig": "projects/angularity/cva/tsconfig.lib.json"
18+
"tsConfig": "projects/angularity/forms/tsconfig.lib.json"
1919
}
2020
},
2121
"defaultConfiguration": "production"
2222
},
2323
"test": {
2424
"executor": "@angular-devkit/build-angular:karma",
2525
"options": {
26-
"tsConfig": "projects/angularity/cva/tsconfig.spec.json",
26+
"tsConfig": "projects/angularity/forms/tsconfig.spec.json",
2727
"polyfills": ["zone.js", "zone.js/testing"]
2828
}
2929
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './value-accessing';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { inject, Injectable } from '@angular/core';
2+
import { ControlValueAccessor } from '@angular/forms';
3+
4+
import { ComponentValueAccessorHost } from './host';
5+
6+
@Injectable()
7+
export class ComponentValueAccessor implements ControlValueAccessor {
8+
private host = inject(ComponentValueAccessorHost, { self: true });
9+
writeValue(value: unknown): void {
10+
this.host.valueInput$.next(value);
11+
}
12+
registerOnChange(fn: (value: unknown) => void): void {
13+
this.host.valueChange$.subscribe({ next: fn });
14+
}
15+
registerOnTouched(fn: () => void): void {
16+
this.host.touched$.subscribe({ next: fn });
17+
}
18+
setDisabledState(disabled: boolean): void {
19+
this.host.disabled$?.next(disabled);
20+
}
21+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Injectable } from '@angular/core';
2+
import { SubjectLike, Subscribable } from 'rxjs';
3+
4+
@Injectable()
5+
export abstract class ComponentValueAccessorHost<T = any> {
6+
abstract valueInput$: SubjectLike<T>;
7+
abstract valueChange$: Subscribable<T>;
8+
abstract touched$: Subscribable<void>;
9+
disabled$?: SubjectLike<boolean>;
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './accessor';
2+
export * from './host';
3+
export * from './provide';

0 commit comments

Comments
 (0)