Skip to content

Commit b4dd2c8

Browse files
feat(component): deprecate ReactiveComponentModule (#3451)
* feat(component): deprecate ReactiveComponentModule * chore: replace absolute links
1 parent a6b4b49 commit b4dd2c8

File tree

6 files changed

+131
-69
lines changed

6 files changed

+131
-69
lines changed

modules/component/src/reactive-component.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { NgModule } from '@angular/core';
22
import { LetModule } from './let/let.module';
33
import { PushModule } from './push/push.module';
44

5+
/**
6+
* @deprecated `ReactiveComponentModule` is deprecated in favor of `LetModule` and `PushModule`.
7+
* See the {@link https://ngrx.io/guide/migration/v14#reactivecomponentmodule migration guide}
8+
* for more information.
9+
*/
510
@NgModule({
611
exports: [LetModule, PushModule],
712
})

modules/schematics/src/ngrx-push-migration/index.spec.ts

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ describe('NgrxPush migration', () => {
7676
});
7777
});
7878

79-
describe('importReactiveComponentModule', () => {
80-
it('should import ReactiveComponentModule when BrowserModule is imported', async () => {
79+
describe('importPushModule', () => {
80+
it('should import PushModule when BrowserModule is imported', async () => {
8181
appTree.create(
8282
'./sut.module.ts',
8383
`
@@ -100,15 +100,11 @@ describe('NgrxPush migration', () => {
100100
.toPromise();
101101

102102
const actual = tree.readContent('./sut.module.ts');
103-
expect(actual).toMatch(
104-
/imports: \[ BrowserModule, ReactiveComponentModule \],/
105-
);
106-
expect(actual).toMatch(
107-
/import { ReactiveComponentModule } from '@ngrx\/component'/
108-
);
103+
expect(actual).toMatch(/imports: \[ BrowserModule, PushModule \],/);
104+
expect(actual).toMatch(/import { PushModule } from '@ngrx\/component'/);
109105
});
110106

111-
it('should import ReactiveComponentModule when CommonModule is imported', async () => {
107+
it('should import PushModule when CommonModule is imported', async () => {
112108
appTree.create(
113109
'./sut.module.ts',
114110
`
@@ -131,15 +127,11 @@ describe('NgrxPush migration', () => {
131127
.toPromise();
132128

133129
const actual = tree.readContent('./sut.module.ts');
134-
expect(actual).toMatch(
135-
/imports: \[ CommonModule, ReactiveComponentModule \],/
136-
);
137-
expect(actual).toMatch(
138-
/import { ReactiveComponentModule } from '@ngrx\/component'/
139-
);
130+
expect(actual).toMatch(/imports: \[ CommonModule, PushModule \],/);
131+
expect(actual).toMatch(/import { PushModule } from '@ngrx\/component'/);
140132
});
141133

142-
it("should not import ReactiveComponentModule when it doesn't need to", async () => {
134+
it("should not import PushModule when it doesn't need to", async () => {
143135
appTree.create(
144136
'./sut.module.ts',
145137
`
@@ -158,17 +150,15 @@ describe('NgrxPush migration', () => {
158150
.toPromise();
159151

160152
const actual = tree.readContent('./sut.module.ts');
153+
expect(actual).not.toMatch(/imports: \[ CommonModule, PushModule \],/);
161154
expect(actual).not.toMatch(
162-
/imports: \[ CommonModule, ReactiveComponentModule \],/
163-
);
164-
expect(actual).not.toMatch(
165-
/import { ReactiveComponentModule } from '@ngrx\/component'/
155+
/import { PushModule } from '@ngrx\/component'/
166156
);
167157
});
168158
});
169159

170-
describe('exportReactiveComponentModule', () => {
171-
it('should export ReactiveComponentModule when BrowserModule is exported', async () => {
160+
describe('exportPushModule', () => {
161+
it('should export PushModule when BrowserModule is exported', async () => {
172162
appTree.create(
173163
'./sut.module.ts',
174164
`
@@ -191,15 +181,11 @@ describe('NgrxPush migration', () => {
191181
.toPromise();
192182

193183
const actual = tree.readContent('./sut.module.ts');
194-
expect(actual).toMatch(
195-
/exports: \[ BrowserModule, ReactiveComponentModule \],/
196-
);
197-
expect(actual).toMatch(
198-
/import { ReactiveComponentModule } from '@ngrx\/component'/
199-
);
184+
expect(actual).toMatch(/exports: \[ BrowserModule, PushModule \],/);
185+
expect(actual).toMatch(/import { PushModule } from '@ngrx\/component'/);
200186
});
201187

202-
it('should export ReactiveComponentModule when CommonModule is exported', async () => {
188+
it('should export PushModule when CommonModule is exported', async () => {
203189
appTree.create(
204190
'./sut.module.ts',
205191
`
@@ -222,15 +208,11 @@ describe('NgrxPush migration', () => {
222208
.toPromise();
223209

224210
const actual = tree.readContent('./sut.module.ts');
225-
expect(actual).toMatch(
226-
/exports: \[ CommonModule, ReactiveComponentModule \],/
227-
);
228-
expect(actual).toMatch(
229-
/import { ReactiveComponentModule } from '@ngrx\/component'/
230-
);
211+
expect(actual).toMatch(/exports: \[ CommonModule, PushModule \],/);
212+
expect(actual).toMatch(/import { PushModule } from '@ngrx\/component'/);
231213
});
232214

233-
it("should not export ReactiveComponentModule when it doesn't need to", async () => {
215+
it("should not export PushModule when it doesn't need to", async () => {
234216
appTree.create(
235217
'./sut.module.ts',
236218
`
@@ -249,11 +231,9 @@ describe('NgrxPush migration', () => {
249231
.toPromise();
250232

251233
const actual = tree.readContent('./sut.module.ts');
234+
expect(actual).not.toMatch(/exports: \[ CommonModule, PushModule \],/);
252235
expect(actual).not.toMatch(
253-
/exports: \[ CommonModule, ReactiveComponentModule \],/
254-
);
255-
expect(actual).not.toMatch(
256-
/import { ReactiveComponentModule } from '@ngrx\/component'/
236+
/import { PushModule } from '@ngrx\/component'/
257237
);
258238
});
259239
});

modules/schematics/src/ngrx-push-migration/index.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import {
1313
} from '../../schematics-core';
1414

1515
const ASYNC_REGEXP = /\| {0,}async/g;
16-
const REACTIVE_MODULE = 'ReactiveComponentModule';
16+
const PUSH_MODULE = 'PushModule';
1717
const COMPONENT_MODULE = '@ngrx/component';
1818

19-
const reactiveModuleToFind = (node: ts.Node) =>
20-
ts.isIdentifier(node) && node.text === REACTIVE_MODULE;
19+
const pushModuleToFind = (node: ts.Node) =>
20+
ts.isIdentifier(node) && node.text === PUSH_MODULE;
2121

2222
const ngModulesToFind = (node: ts.Node) =>
2323
ts.isIdentifier(node) &&
@@ -46,22 +46,22 @@ export function migrateToNgrxPush(): Rule {
4646
});
4747
}
4848

49-
export function importReactiveComponentModule(): Rule {
49+
export function importPushModule(): Rule {
5050
return (host: Tree) => {
5151
visitTSSourceFiles(host, (sourceFile) => {
5252
let hasCommonModuleOrBrowserModule = false;
53-
let hasReactiveComponentModule = false;
53+
let hasPushModule = false;
5454

5555
visitNgModuleImports(sourceFile, (_, importNodes) => {
5656
hasCommonModuleOrBrowserModule = importNodes.some(ngModulesToFind);
57-
hasReactiveComponentModule = importNodes.some(reactiveModuleToFind);
57+
hasPushModule = importNodes.some(pushModuleToFind);
5858
});
5959

60-
if (hasCommonModuleOrBrowserModule && !hasReactiveComponentModule) {
60+
if (hasCommonModuleOrBrowserModule && !hasPushModule) {
6161
const changes: Change[] = addImportToModule(
6262
sourceFile,
6363
sourceFile.fileName,
64-
REACTIVE_MODULE,
64+
PUSH_MODULE,
6565
COMPONENT_MODULE
6666
);
6767
commitChanges(host, sourceFile.fileName, changes);
@@ -70,22 +70,22 @@ export function importReactiveComponentModule(): Rule {
7070
};
7171
}
7272

73-
export function exportReactiveComponentModule(): Rule {
73+
export function exportPushModule(): Rule {
7474
return (host: Tree) => {
7575
visitTSSourceFiles(host, (sourceFile) => {
7676
let hasCommonModuleOrBrowserModule = false;
77-
let hasReactiveComponentModule = false;
77+
let hasPushModule = false;
7878

7979
visitNgModuleExports(sourceFile, (_, exportNodes) => {
8080
hasCommonModuleOrBrowserModule = exportNodes.some(ngModulesToFind);
81-
hasReactiveComponentModule = exportNodes.some(reactiveModuleToFind);
81+
hasPushModule = exportNodes.some(pushModuleToFind);
8282
});
8383

84-
if (hasCommonModuleOrBrowserModule && !hasReactiveComponentModule) {
84+
if (hasCommonModuleOrBrowserModule && !hasPushModule) {
8585
const changes: Change[] = addExportToModule(
8686
sourceFile,
8787
sourceFile.fileName,
88-
REACTIVE_MODULE,
88+
PUSH_MODULE,
8989
COMPONENT_MODULE
9090
);
9191
commitChanges(host, sourceFile.fileName, changes);
@@ -95,9 +95,5 @@ export function exportReactiveComponentModule(): Rule {
9595
}
9696

9797
export default function (): Rule {
98-
return chain([
99-
migrateToNgrxPush(),
100-
importReactiveComponentModule(),
101-
exportReactiveComponentModule(),
102-
]);
98+
return chain([migrateToNgrxPush(), importPushModule(), exportPushModule()]);
10399
}

projects/ngrx.io/content/guide/component/let.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ import { ReactiveComponentModule } from '@ngrx/component';
3838
export class MyFeatureModule {}
3939
```
4040

41+
<div class="alert is-critical">
42+
43+
`ReactiveComponentModule` is deprecated in favor of `LetModule`.
44+
See the [migration guide](guide/migration/v14#reactivecomponentmodule) for more information.
45+
46+
</div>
47+
4148
## Comparison with `*ngIf` and `async`
4249

4350
The current way of binding an observable to the view looks like this:

projects/ngrx.io/content/guide/component/push.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ import { ReactiveComponentModule } from '@ngrx/component';
3939
export class MyFeatureModule {}
4040
```
4141

42+
<div class="alert is-critical">
43+
44+
`ReactiveComponentModule` is deprecated in favor of `PushModule`.
45+
See the [migration guide](guide/migration/v14#reactivecomponentmodule) for more information.
46+
47+
</div>
48+
4249
## Comparison with `async` Pipe
4350

4451
The current way of binding an observable to the view looks like this:

projects/ngrx.io/content/guide/migration/v14.md

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ AFTER:
6868
- `e` will be thrown error when `obs$` emits error event.
6969
- `e` will be `undefined` when `obs$` emits next/complete event.
7070

71-
#### add ability to pass non-observable values
71+
#### Add ability to pass non-observable values
7272

7373
1. The context of `LetDirective` is strongly typed when `null` or
7474
`undefined` is passed as input.
@@ -105,27 +105,27 @@ BEFORE:
105105

106106
```ts
107107
@Component({
108-
template: `
109-
<p *ngrxLet="numbers as n">{{ n }}</p>
110-
<p>{{ numbers | ngrxPush }}</p>
111-
`,
108+
template: `
109+
<p *ngrxLet="numbers as n">{{ n }}</p>
110+
<p>{{ numbers | ngrxPush }}</p>
111+
`,
112112
})
113113
export class NumbersComponent {
114-
numbers = [1, 2, 3];
114+
numbers = [1, 2, 3];
115115
}
116116
```
117117

118118
AFTER:
119119

120120
```ts
121121
@Component({
122-
template: `
123-
<p *ngrxLet="numbers$ as n">{{ n }}</p>
124-
<p>{{ numbers$ | ngrxPush }}</p>
125-
`,
122+
template: `
123+
<p *ngrxLet="numbers$ as n">{{ n }}</p>
124+
<p>{{ numbers$ | ngrxPush }}</p>
125+
`,
126126
})
127127
export class NumbersComponent {
128-
numbers$ = from([1, 2, 3]);
128+
numbers$ = from([1, 2, 3]);
129129
}
130130
```
131131

@@ -139,3 +139,70 @@ When the schematics are installed, `@ngrx/schematics` is added to the `schematic
139139
<div class="alert is-helpful">
140140
A migration is provided to add `@ngrx/schematics` to the `schematicCollections`.
141141
</div>
142+
143+
## Deprecations
144+
145+
### @ngrx/component
146+
147+
#### ReactiveComponentModule
148+
149+
`ReactiveComponentModule` is deprecated in favor of `LetModule` and `PushModule`.
150+
151+
BEFORE:
152+
153+
```ts
154+
import { ReactiveComponentModule } from '@ngrx/component';
155+
156+
@NgModule({
157+
imports: [
158+
// ... other imports
159+
ReactiveComponentModule,
160+
],
161+
})
162+
export class MyFeatureModule {}
163+
```
164+
165+
AFTER:
166+
167+
If the components declared in the `MyFeatureModule` use only the `*ngrxLet` directive:
168+
169+
```ts
170+
import { LetModule } from '@ngrx/component';
171+
172+
@NgModule({
173+
imports: [
174+
// ... other imports
175+
LetModule,
176+
],
177+
})
178+
export class MyFeatureModule {}
179+
```
180+
181+
If the components declared in the `MyFeatureModule` use only the `ngrxPush` pipe:
182+
183+
```ts
184+
import { PushModule } from '@ngrx/component';
185+
186+
@NgModule({
187+
imports: [
188+
// ... other imports
189+
PushModule,
190+
],
191+
})
192+
export class MyFeatureModule {}
193+
```
194+
195+
If the components declared in the `MyFeatureModule` use both the `*ngrxLet` directive and the `ngrxPush` pipe:
196+
197+
```ts
198+
import { LetModule, PushModule } from '@ngrx/component';
199+
200+
@NgModule({
201+
imports: [
202+
// ... other imports
203+
LetModule,
204+
PushModule,
205+
],
206+
})
207+
export class MyFeatureModule {}
208+
```

0 commit comments

Comments
 (0)