Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ Each Pull Request will contain explanation and steps taken to complete a feature
## Installing Frameworks and Libs

- [Add Boostrap 4](https://github.com/brunolm/angular-how-to/pull/5)
- [Add Mobx (redux-like)](https://github.com/brunolm/angular-how-to/pull/22)
- [Add Redux](https://github.com/brunolm/angular-how-to/pull/14)
- [API call in Redux](https://github.com/brunolm/angular-how-to/pull/16)
- [redux tag](https://github.com/brunolm/angular-how-to/tree/redux)

## Routes

Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
"camelcase-keys": "^4.2.0",
"core-js": "^2.4.1",
"marked": "^0.4.0",
"mobx": "^5.0.3",
"mobx-angular": "^3.0.1",
"ngx-redux-state-props": "0.0.6",
"ngx-take-until-destroy": "^3.0.0",
"redux": "^4.0.0",
Expand Down
15 changes: 15 additions & 0 deletions src/app/about/about-store.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { inject, TestBed } from '@angular/core/testing';

import { AboutStoreService } from './about-store.service';

describe('AboutStoreService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AboutStoreService],
});
});

it('should be created', inject([AboutStoreService], (service: AboutStoreService) => {
expect(service).toBeTruthy();
}));
});
24 changes: 24 additions & 0 deletions src/app/about/about-store.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Injectable } from '@angular/core';
import { action, observable } from 'mobx-angular';

@Injectable({
providedIn: 'root',
})
export class AboutStoreService {
@observable title: string;

constructor() {
this.initialize();
}

@action
private initialize() {
this.title = 'about:hello world';
}

@action
randomTitle() {
// tslint:disable-next-line:no-magic-numbers
this.title = Math.random().toString(32);
}
}
6 changes: 6 additions & 0 deletions src/app/about/about.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
</p>
</div>

<div>
<h3>Mobx</h3>
<p>{{ store?.about?.title }}</p>
<button class="btn btn-primary" (click)="updateTitle()">Change title</button>
</div>

<button (click)="testRedux()" class="btn btn-primary">Test redux</button>
-
<button class="btn btn-primary" (click)="getNasaApod()">APOD</button>
Expand Down
11 changes: 10 additions & 1 deletion src/app/about/about.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { NgxReduxStatePropsService } from 'ngx-redux-state-props';

import { AppState } from '../app-state.model';
import { AppStoreService } from '../app-store.service';
import { AboutActions } from './services/about.actions';

@Component({
Expand All @@ -17,7 +18,11 @@ export class AboutComponent {
- here
- or here`;

constructor(private actions: AboutActions, private redux: NgxReduxStatePropsService<AppState>) {}
constructor(
private actions: AboutActions,
private redux: NgxReduxStatePropsService<AppState>,
public store: AppStoreService,
) {}

get state() {
return this.redux.appState && this.redux.appState.about;
Expand All @@ -30,4 +35,8 @@ export class AboutComponent {
getNasaApod() {
this.actions.getNasaApod();
}

updateTitle() {
this.store.about.randomTitle();
}
}
15 changes: 15 additions & 0 deletions src/app/app-store.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { inject, TestBed } from '@angular/core/testing';

import { AppStoreService } from './app-store.service';

describe('AppStoreService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [AppStoreService],
});
});

it('should be created', inject([AppStoreService], (service: AppStoreService) => {
expect(service).toBeTruthy();
}));
});
18 changes: 18 additions & 0 deletions src/app/app-store.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Injectable } from '@angular/core';

import { AboutStoreService } from './about/about-store.service';
import { ContactStoreService } from './contact/contact-store.service';
import { HeroesStoreService } from './heroes/heroes-store.service';
import { TutorialsStoreService } from './tutorials/tutorials-store.service';

@Injectable({
providedIn: 'root',
})
export class AppStoreService {
constructor(
public about: AboutStoreService,
public contact: ContactStoreService,
public heroes: HeroesStoreService,
public tutorials: TutorialsStoreService,
) {}
}
2 changes: 2 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { NgReduxRouter, routerReducer } from '@angular-redux/router';
import { DevToolsExtension, NgRedux } from '@angular-redux/store';
import { Component } from '@angular/core';
import { configure } from 'mobx';
import { combineReducers } from 'redux';
import thunk from 'redux-thunk';

Expand Down Expand Up @@ -30,6 +31,7 @@ export class AppComponent {
this.devTools.isEnabled() ? [this.devTools.enhancer()] : undefined,
);
this.ngReduxRouter.initialize();
configure({ enforceActions: 'strict' });
}

createReducer(ReducerService) {
Expand Down
9 changes: 8 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@ import { NgReduxRouterModule } from '@angular-redux/router';
import { NgReduxModule } from '@angular-redux/store';
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { MobxAngularModule } from 'mobx-angular';
import { NgxReduxStatePropsModule } from 'ngx-redux-state-props';

import { AboutStoreService } from './about/about-store.service';
import { AppStoreService } from './app-store.service';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app.router';
import { ContactStoreService } from './contact/contact-store.service';
import { HeroesStoreService } from './heroes/heroes-store.service';
import { SharedModule } from './shared/shared.module';
import { TutorialsStoreService } from './tutorials/tutorials-store.service';

@NgModule({
declarations: [AppComponent],
imports: [
AppRoutingModule,
BrowserModule,
SharedModule,
MobxAngularModule,
NgReduxModule,
NgReduxRouterModule.forRoot(),
NgxReduxStatePropsModule,
],
providers: [],
providers: [AppStoreService, AboutStoreService, ContactStoreService, HeroesStoreService, TutorialsStoreService],
bootstrap: [AppComponent],
})
export class AppModule {}
15 changes: 15 additions & 0 deletions src/app/contact/contact-store.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { inject, TestBed } from '@angular/core/testing';

import { ContactStoreService } from './contact-store.service';

describe('ContactStoreService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [ContactStoreService],
});
});

it('should be created', inject([ContactStoreService], (service: ContactStoreService) => {
expect(service).toBeTruthy();
}));
});
6 changes: 6 additions & 0 deletions src/app/contact/contact-store.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class ContactStoreService {}
5 changes: 5 additions & 0 deletions src/app/contact/form/form.component.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<div>
<h3>About page title is</h3>
<p>{{ store?.about?.title }}</p>
</div>
<hr>
<form (ngSubmit)="submit()" [formGroup]="contactForm">
<div class="form-group">
<label for="email"></label>
Expand Down
4 changes: 3 additions & 1 deletion src/app/contact/form/form.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Component } from '@angular/core';
import { FormBuilder, Validators } from '@angular/forms';

import { AppStoreService } from '../../app-store.service';

@Component({
selector: 'app-form',
templateUrl: './form.component.html',
Expand All @@ -12,7 +14,7 @@ export class FormComponent {
message: this.formBuilder.control('', Validators.required),
});

constructor(private formBuilder: FormBuilder) {}
constructor(private formBuilder: FormBuilder, public store: AppStoreService) {}

submit() {
if (this.contactForm.invalid) {
Expand Down
15 changes: 15 additions & 0 deletions src/app/heroes/heroes-store.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { inject, TestBed } from '@angular/core/testing';

import { HeroesStoreService } from './heroes-store.service';

describe('HeroesStoreService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [HeroesStoreService],
});
});

it('should be created', inject([HeroesStoreService], (service: HeroesStoreService) => {
expect(service).toBeTruthy();
}));
});
6 changes: 6 additions & 0 deletions src/app/heroes/heroes-store.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class HeroesStoreService {}
15 changes: 15 additions & 0 deletions src/app/tutorials/tutorials-store.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { inject, TestBed } from '@angular/core/testing';

import { TutorialsStoreService } from './tutorials-store.service';

describe('TutorialsStoreService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [TutorialsStoreService],
});
});

it('should be created', inject([TutorialsStoreService], (service: TutorialsStoreService) => {
expect(service).toBeTruthy();
}));
});
6 changes: 6 additions & 0 deletions src/app/tutorials/tutorials-store.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root',
})
export class TutorialsStoreService {}