Skip to content

Commit fdc88a5

Browse files
[WIP] App improvements (#31)
* App improvements * Epics: don;t refetch HTTP data if we already have it * Animal Lists: add a fractal counter component to each row. * Import Fluz-Standard-Action for stronger action typings * More refactoring * remove redundancy in folder/file names. * better normalize store data. * better fractal stuff * Basic implementation of fractal stuff. TODO: * move utils/fractal.ts into NgRedux proper * move form/composeReducers into NgRedux proper * clean up subselect implementation * move fractalReducer stuff into NgRedux proper. * unit test the demo * RFC e-schultz, nk, ke, as with intent to publish in 6.4. * consider decorator implementation. * update to 6.4 alpha * use yarn * Remove obsolete e2e tests, fix yarn on CI * animal component unit tests * update to 6.4.0
1 parent f219b83 commit fdc88a5

Some content is hidden

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

64 files changed

+653
-386
lines changed

circle.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
machine:
22
node:
33
version: 6.9.5
4-
post:
5-
- wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
6-
- sudo sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
7-
- sudo apt-get update
8-
- sudo apt-get install google-chrome-stable
4+
5+
dependencies:
6+
# Circle CI's preinstalled yarn doesn't work with @angular/cli. Never versions
7+
# of yarn do.
8+
pre:
9+
- curl -o- -L https://yarnpkg.com/install.sh | bash
10+
override:
11+
- yarn
912

1013
test:
1114
override:
12-
- ng lint --type-check && ng test --single-run && ng e2e
15+
- yarn test

e2e/app.e2e-spec.ts

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

e2e/app.po.ts

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

e2e/tsconfig.e2e.json

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

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"ng": "ng",
77
"start": "ng serve",
88
"build": "ng build",
9-
"test": "ng test",
10-
"lint": "ng lint --type-check",
11-
"e2e": "ng e2e"
9+
"test": "ng lint --type-check && ng test --single-run"
1210
},
1311
"engines": {
1412
"node": ">=6.9.5"
@@ -17,7 +15,7 @@
1715
"dependencies": {
1816
"@angular-redux/form": "^6.3.0",
1917
"@angular-redux/router": "^6.3.0",
20-
"@angular-redux/store": "^6.3.0",
18+
"@angular-redux/store": "^6.4.0",
2119
"@angular/common": "^4.1.0",
2220
"@angular/compiler": "^4.1.0",
2321
"@angular/core": "^4.1.0",
@@ -27,6 +25,8 @@
2725
"@angular/platform-browser-dynamic": "^4.1.0",
2826
"@angular/router": "^4.1.0",
2927
"core-js": "^2.4.1",
28+
"flux-standard-action": "^1.2.0",
29+
"ramda": "^0.23.0",
3030
"redux": "^3.6.0",
3131
"redux-logger": "^3.0.1",
3232
"redux-observable": "^0.14.1",

src/app/animals/animal-list/animal-list.component.css

Whitespace-only changes.

src/app/animals/animal-list/animal-list.component.html

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.header { display: flex; }
2+
.header-cell { flex-basis: 25%; font-weight: bold; }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<h2>We have {{ animalsName }}!</h2>
2+
3+
<zoo-spinner *ngIf="loading | async">
4+
</zoo-spinner>
5+
6+
<section class="header">
7+
<div class="header-cell">Name</div>
8+
<div class="header-cell">Ticket Price</div>
9+
<div class="header-cell">Tickets</div>
10+
<div class="header-cell">Subtotal</div>
11+
</section>
12+
<zoo-animal
13+
*ngFor="let animal of animals | async; trackBy:getKey"
14+
[animalType]=animalType
15+
[key]=getKey(null,animal)>
16+
</zoo-animal>
17+
18+
<zoo-error-well *ngIf="error | async">
19+
</zoo-error-well>

src/app/animals/animal-list/animal-list.component.spec.ts renamed to src/app/animals/animal-list/component.spec.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1+
import { Component, Input } from '@angular/core';
12
import { TestBed, async } from '@angular/core/testing';
23
import { RouterTestingModule } from '@angular/router/testing';
34
import { By } from '@angular/platform-browser';
4-
import { AnimalListComponent } from './animal-list.component';
5-
import { CoreModule } from '../../core/core.module';
5+
import { AnimalListComponent } from './component';
6+
import { CoreModule } from '../../core/module';
7+
import { AnimalType } from '../model';
68

7-
describe('AppComponent', () => {
9+
@Component({ selector: 'zoo-animal', template: '' })
10+
class MockAnimalComponent {
11+
@Input() key: string
12+
@Input() animalType: AnimalType
13+
}
14+
15+
describe('AnimalListComponent', () => {
816
beforeEach(async(() => {
917
TestBed.configureTestingModule({
10-
declarations: [AnimalListComponent],
18+
declarations: [AnimalListComponent, MockAnimalComponent],
1119
imports: [CoreModule],
1220
}).compileComponents();
1321
}));
1422

1523
it(`should have as title 'Welcome to the Zoo'`, async(() => {
1624
const fixture = TestBed.createComponent(AnimalListComponent);
17-
const app = fixture.debugElement.componentInstance;
25+
const animalList = fixture.debugElement.componentInstance;
1826

19-
app.animalsName = 'Wallabies';
27+
animalList.animalsName = 'Wallabies';
28+
animalList.animalType = 'WALLABIES';
2029
fixture.detectChanges();
2130

2231
const titleElement = fixture.debugElement.query(By.css('h2'));
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
import { Component, Input, ChangeDetectionStrategy } from '@angular/core';
22
import { Observable } from 'rxjs/Observable';
3+
import { IAnimal } from '../model';
34

45
@Component({
56
selector: 'zoo-animal-list',
6-
templateUrl: './animal-list.component.html',
7-
styleUrls: ['./animal-list.component.css'],
7+
templateUrl: './component.html',
8+
styleUrls: ['./component.css'],
89
changeDetection: ChangeDetectionStrategy.OnPush,
910
})
1011
export class AnimalListComponent {
1112
@Input() animalsName: string;
12-
@Input() animals: Observable<any[]>;
13+
@Input() animalType: string;
14+
@Input() animals: Observable<IAnimal[]>;
1315
@Input() loading: Observable<boolean>;
1416
@Input() error: Observable<any>;
1517

1618
// Since we're observing an array of items, we need to set up a 'trackBy'
1719
// parameter so Angular doesn't tear down and rebuild the list's DOM every
1820
// time there's an update.
19-
getAnimalName(_, animal) {
20-
return animal.name;
21+
getKey(_, animal: IAnimal) {
22+
return animal.id;
2123
}
2224
}

src/app/animals/animal.actions.ts

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

src/app/animals/animal.epics.ts

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

src/app/animals/animal.module.ts

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

src/app/animals/animal.reducer.ts

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

src/app/animals/animal.service.ts

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

src/app/animals/animal/component.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:host { display: flex; }
2+
div { flex-basis: 25%; }

src/app/animals/animal/component.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<div>{{ name$ | async }}</div>
2+
<div>{{ ticketPrice$ | async }}</div>
3+
<div>
4+
<zoo-counter
5+
[count]="numTickets$ | async"
6+
(increment)=addTicket()
7+
(decrement)=removeTicket()>
8+
</zoo-counter>
9+
</div>
10+
<div>${{ subTotal$ | async }}

0 commit comments

Comments
 (0)