Skip to content
This repository was archived by the owner on Jan 18, 2024. It is now read-only.

Commit 58644d2

Browse files
docs: add store tutorial example and tweak build to support examples (ngrx#1417)
1 parent 958f3b6 commit 58644d2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1748
-2821
lines changed

Diff for: .circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ jobs:
9595
key: *docs_cache_key
9696
- run: yarn setup
9797
- run: npm rebuild node-sass
98-
- run: yarn build-for next
98+
- run: yarn build-for next && yarn copy-404-page
9999
- run: cp -rf src/extra-files/next/. dist/ngrx.io/
100100
# Store artifacts from build
101101
- persist_to_workspace:

Diff for: .prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/modules/schematics/src/*/files/*
33
/modules/**/schematics/**/files/*
44
/tmp
5+
/projects/ngrx.io
56
package-lock.json
67
package.json
78
yarn.lock

Diff for: projects/ngrx.io/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ yarn-error.log
4040
/e2e/*.js
4141
/e2e/*.map
4242
protractor-results*.txt
43+
!e2e/protractor.conf.js
4344

4445
# System Files
4546
.DS_Store

Diff for: projects/ngrx.io/angular.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"cli": {
66
"packageManager": "yarn"
77
},
8-
"newProjectRoot": "projects",
8+
"newProjectRoot": "content/examples",
99
"projects": {
1010
"site": {
1111
"root": "",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { AppPage } from './app.po';
2+
3+
describe('workspace-project App', () => {
4+
let page: AppPage;
5+
6+
beforeEach(() => {
7+
page = new AppPage();
8+
});
9+
10+
it('should display welcome message', () => {
11+
page.navigateTo();
12+
expect(page.getParagraphText()).toEqual('Welcome to store-tutorial!');
13+
});
14+
});

Diff for: projects/ngrx.io/content/examples/store/example-config.json

Whitespace-only changes.

Diff for: projects/ngrx.io/content/examples/store/src/app/app.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h1>NgRx Tutorial</h1>
2+
3+
<!-- #docregion counter -->
4+
<app-my-counter></app-my-counter>
5+
<!-- #enddocregion counter -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { TestBed, async } from '@angular/core/testing';
2+
import { AppComponent } from './app.component';
3+
4+
describe('AppComponent', () => {
5+
beforeEach(async(() => {
6+
TestBed.configureTestingModule({
7+
declarations: [AppComponent],
8+
}).compileComponents();
9+
}));
10+
11+
it('should create the app', () => {
12+
const fixture = TestBed.createComponent(AppComponent);
13+
const app = fixture.debugElement.componentInstance;
14+
expect(app).toBeTruthy();
15+
});
16+
17+
it(`should have as title 'store-tutorial'`, () => {
18+
const fixture = TestBed.createComponent(AppComponent);
19+
const app = fixture.debugElement.componentInstance;
20+
expect(app.title).toEqual('store-tutorial');
21+
});
22+
23+
it('should render title in a h1 tag', () => {
24+
const fixture = TestBed.createComponent(AppComponent);
25+
fixture.detectChanges();
26+
const compiled = fixture.debugElement.nativeElement;
27+
expect(compiled.querySelector('h1').textContent).toContain(
28+
'Welcome to store-tutorial!'
29+
);
30+
});
31+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-root',
5+
templateUrl: './app.component.html',
6+
styleUrls: ['./app.component.css'],
7+
})
8+
export class AppComponent {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// #docregion
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { NgModule } from '@angular/core';
4+
5+
import { AppComponent } from './app.component';
6+
7+
import { StoreModule } from '@ngrx/store';
8+
import { counterReducer } from './counter.reducer';
9+
10+
@NgModule({
11+
declarations: [AppComponent],
12+
imports: [
13+
BrowserModule,
14+
StoreModule.forRoot({ count: counterReducer })
15+
],
16+
providers: [],
17+
bootstrap: [AppComponent],
18+
})
19+
export class AppModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// #docregion
2+
import { BrowserModule } from '@angular/platform-browser';
3+
import { NgModule } from '@angular/core';
4+
5+
import { AppComponent } from './app.component';
6+
7+
// #docregion imports
8+
import { StoreModule } from '@ngrx/store';
9+
import { counterReducer } from './counter.reducer';
10+
// #enddocregion imports
11+
import { MyCounterComponent } from './my-counter/my-counter.component';
12+
13+
@NgModule({
14+
declarations: [AppComponent, MyCounterComponent],
15+
imports: [
16+
BrowserModule,
17+
StoreModule.forRoot({ count: counterReducer })
18+
],
19+
providers: [],
20+
bootstrap: [AppComponent],
21+
})
22+
export class AppModule {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// #docregion
2+
import { Action } from '@ngrx/store';
3+
4+
export enum ActionTypes {
5+
Increment = '[Counter Component] Increment',
6+
Decrement = '[Counter Component] Decrement',
7+
Reset = '[Counter Component] Reset',
8+
}
9+
10+
export class Increment implements Action {
11+
readonly type = ActionTypes.Increment;
12+
}
13+
14+
export class Decrement implements Action {
15+
readonly type = ActionTypes.Decrement;
16+
}
17+
18+
export class Reset implements Action {
19+
readonly type = ActionTypes.Reset;
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// #docregion
2+
import { Action } from '@ngrx/store';
3+
import { ActionTypes } from './counter.actions';
4+
5+
export const initialState = 0;
6+
7+
export function counterReducer(state = initialState, action: Action) {
8+
switch (action.type) {
9+
case ActionTypes.Increment:
10+
return state + 1;
11+
12+
case ActionTypes.Decrement:
13+
return state - 1;
14+
15+
case ActionTypes.Reset:
16+
return 0;
17+
18+
default:
19+
return state;
20+
}
21+
}

Diff for: projects/ngrx.io/content/examples/store/src/app/my-counter/my-counter.component.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<button (click)="increment()">Increment</button>
2+
3+
<div>Current Count: {{ count$ | async }}</div>
4+
5+
<button (click)="decrement()">Decrement</button>
6+
7+
<button (click)="reset()">Reset Counter</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
2+
3+
import { MyCounterComponent } from './my-counter.component';
4+
5+
describe('MyCounterComponent', () => {
6+
let component: MyCounterComponent;
7+
let fixture: ComponentFixture<MyCounterComponent>;
8+
9+
beforeEach(async(() => {
10+
TestBed.configureTestingModule({
11+
declarations: [MyCounterComponent],
12+
}).compileComponents();
13+
}));
14+
15+
beforeEach(() => {
16+
fixture = TestBed.createComponent(MyCounterComponent);
17+
component = fixture.componentInstance;
18+
fixture.detectChanges();
19+
});
20+
21+
it('should create', () => {
22+
expect(component).toBeTruthy();
23+
});
24+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { Component } from '@angular/core';
2+
import { Store, select } from '@ngrx/store';
3+
import { Observable } from 'rxjs';
4+
import { Increment, Decrement, Reset } from '../counter.actions';
5+
6+
@Component({
7+
selector: 'app-my-counter',
8+
templateUrl: './my-counter.component.html',
9+
styleUrls: ['./my-counter.component.css'],
10+
})
11+
export class MyCounterComponent {
12+
count$: Observable<number>;
13+
14+
constructor(private store: Store<{ count: number }>) {
15+
this.count$ = store.pipe(select('count'));
16+
}
17+
18+
increment() {
19+
this.store.dispatch(new Increment());
20+
}
21+
22+
decrement() {
23+
this.store.dispatch(new Decrement());
24+
}
25+
26+
reset() {
27+
this.store.dispatch(new Reset());
28+
}
29+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>NgRx Tutorial</title>
6+
<base href="/">
7+
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
<link rel="icon" type="image/x-icon" href="favicon.ico">
10+
</head>
11+
<body>
12+
<app-root></app-root>
13+
</body>
14+
</html>

Diff for: projects/ngrx.io/content/examples/store/src/main.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { enableProdMode } from '@angular/core';
2+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
3+
4+
import { AppModule } from './app/app.module';
5+
import { environment } from './environments/environment';
6+
7+
if (environment.production) {
8+
enableProdMode();
9+
}
10+
11+
platformBrowserDynamic()
12+
.bootstrapModule(AppModule)
13+
.catch(err => console.error(err));
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"description": "Tutorial",
3+
"files": ["!**/*.d.ts", "!**/*.js"]
4+
}

0 commit comments

Comments
 (0)