@ng-atomic/core 17.0.4 → 17.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +42 -32
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,59 +1,69 @@
1
1
  # @ng-atomic/core
2
- `@ng-atomic/core`は
3
-
4
- ## Concept
5
- - Injectable Component
6
- - Action and Effect
2
+ `@ng-atomic/core` is a library that enables dependency injection for components.
7
3
 
8
4
  ## Install
9
5
  ```sh
10
6
  $ npm i @ng-atomic/core
11
7
  ```
12
8
 
13
- ## Example
14
-
9
+ ## Usage
15
10
  ```ts
16
- @Directive({standalone: true, selector: 'example'})
11
+ import { Component, Directive, inject, input } from '@angular/core';
12
+ import { bootstrapApplication } from '@angular/platform-browser';
13
+ import { Effect, TokenizedType, provideComponent, InjectableComponent } from '@ng-atomic/core';
14
+ import { NgAtomicComponent } from '@ng-atomic/core';
15
+ import 'zone.js';
16
+
17
+ export enum ActionId {
18
+ CREATE = 'Create',
19
+ }
20
+
21
+ @TokenizedType()
22
+ @Directive({ standalone: true, selector: 'example' })
17
23
  export class ExampleComponentStore extends InjectableComponent {
18
- @Input() name: string;
24
+ static readonly ActionId = ActionId;
25
+ readonly name = input<string>('');
19
26
  }
20
27
 
21
28
  @Component({
22
29
  standalone: true,
23
- selector: 'example',
24
- hostDirectives: [ExampleComponentStore],
25
- template: `<button (click)="onButtonClick()">{{ store.name }}</button>`
30
+ selector: `example`,
31
+ template: `
32
+ <div>{{ store.name() }}</div>
33
+ <button (click)="onClick()">ADD</button>
34
+ `,
35
+ hostDirectives: [
36
+ {
37
+ directive: ExampleComponentStore,
38
+ inputs: ['name'],
39
+ },
40
+ ],
26
41
  })
27
42
  export class ExampleComponent extends NgAtomicComponent {
28
- protected store = inject(ExampleComponentStore);
43
+ protected readonly store = inject(ExampleComponentStore);
29
44
 
30
- protected onButtonClick() {
31
- this.dispatch({
32
- id: ActionId.BUTTON_CLICK,
33
- payload: 'Hello World!',
34
- });
45
+ protected onClick() {
46
+ this.dispatch({ id: ActionId.CREATE, payload: 'ADD' });
35
47
  }
36
48
  }
37
49
 
38
50
  @Component({
51
+ selector: 'app-root',
39
52
  standalone: true,
40
- selector: 'example',
41
- imports: [
42
- // Import Injectable Component
43
- ExampleComponentStore
44
- ],
45
- template: `<example [name]="'example'" (action)="dispatch($event)" injectable/>`,
46
- provider: [
47
- // Provide Component Implementation
48
- provideComponent(ExampleComponentStore, () => ExampleComponent),
49
- ],
53
+ imports: [ExampleComponentStore],
54
+ template: `
55
+ <example [name]="'test'" (action)="dispatch($event)" injectable/>
56
+ `,
57
+ providers: [provideComponent(ExampleComponentStore, () => ExampleComponent)],
50
58
  })
51
- export class AppComponent extends NgAtomicComponent {
52
- @Effect(ExampleComponent.ActionId.BUTTON_CLICK)
53
- protected onButtonClick(message: string) {
54
- alert(message);
59
+ export class App extends NgAtomicComponent {
60
+ @Effect(ExampleComponentStore.ActionId.CREATE)
61
+ protected create() {
62
+ alert('created!!');
55
63
  }
56
64
  }
65
+
66
+ bootstrapApplication(App);
57
67
  ```
58
68
 
59
69
  # LISENCE
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-atomic/core",
3
- "version": "17.0.4",
3
+ "version": "17.2.0",
4
4
  "homepage": "https://github.com/xx-machina/plaform/tree/main/packages/@ng-atomic/core",
5
5
  "repository": {
6
6
  "type": "git",