Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk ngrx #38

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c980a35
refdactor date store with new sdk
lucienbertin Nov 20, 2018
42071cd
refactor location store with new sdk
lucienbertin Nov 20, 2018
8fdefc9
rewrote router trigger with new sdk
lucienbertin Nov 20, 2018
8294305
fix all the fixes
lucienbertin Nov 20, 2018
89027b9
clean up dode
lucienbertin Nov 20, 2018
1dca308
rem /store form @meteo/core
lucienbertin Nov 20, 2018
9c8ac2f
added a forecast module
lucienbertin Nov 21, 2018
1312202
added ngrx/entity
lucienbertin Nov 21, 2018
89dd639
import forecast store module
lucienbertin Nov 21, 2018
680b618
add id on forecast
lucienbertin Nov 21, 2018
fc88927
add generic forecast reducer using ngrx/entity
lucienbertin Nov 21, 2018
fafb245
added selectors
lucienbertin Nov 21, 2018
3677488
forecasts components use the define selectors
lucienbertin Nov 21, 2018
a4087fb
fix elevation shjenanigans
lucienbertin Nov 21, 2018
67cb384
minor
lucienbertin Nov 21, 2018
62fc322
use sdk's commands injectable
lucienbertin Nov 21, 2018
0c153ef
use conductor
lucienbertin Nov 21, 2018
308409e
fix call operator synthax
lucienbertin Nov 22, 2018
4ed769c
call operator shenanigans
lucienbertin Nov 23, 2018
21c38c8
dip - basic shematics integrated to this repo
lucienbertin Jan 22, 2019
0c31fa9
Merge pull request #40 from lucienbertin/schematics
lucienbertin Feb 26, 2019
6d50a5e
Merge pull request #39 from lucienbertin/forecast.store
lucienbertin Feb 26, 2019
7876e40
update some dependencies
lucienbertin Feb 26, 2019
3daf6c4
pck lock
lucienbertin Feb 26, 2019
520d596
update @lf-sdk/ng to 2-beta
lucienbertin Feb 26, 2019
46fae0a
new ngrx sdk synthax
lucienbertin Feb 26, 2019
60652e2
new ngrx sdk synthax
lucienbertin Feb 26, 2019
720a94f
fix all ze bugs
lucienbertin Feb 26, 2019
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
8 changes: 5 additions & 3 deletions applications/home/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RouterModule } from '@angular/router';
import { MfRouterModule, redirectRoute } from './router';
import { LocaleModule } from '@meteo/core';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ConductorModule } from '@lucca-front-sdk/ng/ngrx';

@NgModule({
declarations: [
Expand All @@ -21,9 +22,10 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
ForecastModule,
RouterModule.forRoot(redirectRoute),
MfRouterModule,
StoreModule.forRoot({}),
EffectsModule.forRoot([]),
StoreDevtoolsModule.instrument({}),
StoreDevtoolsModule.instrument({
name: 'meteo-fiable',
}),
ConductorModule.forRoot(),
LocaleModule,
BrowserAnimationsModule,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
</div>
<mf-timeline></mf-timeline>

<mf-forecast-meta [forecast]="forecast$ | async"></mf-forecast-meta>
<mf-forecast-meta [forecast]="forecast$ | async"></mf-forecast-meta>
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
import { Component, OnInit } from '@angular/core';
import { Observable, combineLatest } from 'rxjs';
import { delay } from 'rxjs/operators';
import { Moment } from 'moment';

import { Store } from '@ngrx/store';
import { IGmapGeocode, IForecast, Forecast, Weather } from '@meteo/models';
import { ILocationStore, IDateStore } from '@meteo/store';
import { Store, select } from '@ngrx/store';
import { IForecast } from '@meteo/models';
import { selectCurrentForecast } from '@meteo/store';

@Component({
selector: 'mf-forecast',
templateUrl: 'forecast.component.html',
styleUrls: ['forecast.component.scss'],
})
export class ForecastComponent implements OnInit {
location$: Observable<IGmapGeocode>;
date$: Observable<Moment>;
forecast$: Observable<IForecast>;
constructor(
private store$: Store<ILocationStore & IDateStore>,
private store$: Store<any>,
) {}
ngOnInit() {
this.initObs();
}
initObs() {
this.initStoreObs();
this.initForecastObs();
}
initStoreObs() {
this.location$ = this.store$.select(s => s.location).pipe(delay(0));
this.date$ = this.store$.select(s => s.date).pipe(delay(0));
}
initForecastObs() {
this.forecast$ = combineLatest(
this.location$,
this.date$,
(geocode, date) => {
if (!!geocode && !!date) {
return new Forecast(geocode, date, Weather.sunny);
}
return undefined;
}
)
this.forecast$ = this.store$.pipe(
select(selectCurrentForecast),
);
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,25 @@
import { Component, OnInit } from '@angular/core';
import { Observable, combineLatest } from 'rxjs';
import { delay } from 'rxjs/operators';
import * as moment from 'moment';

import { Store } from '@ngrx/store';
import { IGmapGeocode, IForecast, Forecast, Weather } from '@meteo/models';
import { ILocationStore, IDateStore } from '@meteo/store';
const timeline = [
{ d: -1, weather: Weather.rainy },
{ d: 0, weather: Weather.sunny },
{ d: 1, weather: Weather.sunny },
{ d: 2, weather: Weather.cloudy },
{ d: 3, weather: undefined },
{ d: 4, weather: undefined },
{ d: 5, weather: undefined },
];
import { Store, select } from '@ngrx/store';
import { IForecast } from '@meteo/models';
import { selectForecasts } from '@meteo/store';
@Component({
selector: 'mf-timeline',
templateUrl: 'timeline.component.html',
styleUrls: ['timeline.component.scss'],
})
export class TimelineComponent implements OnInit {
location$: Observable<IGmapGeocode>;
date$: Observable<moment.Moment>;
timeline$: Observable<IForecast[]>;
constructor(
private store$: Store<ILocationStore & IDateStore>,
private store$: Store<any>,
) {}
ngOnInit() {
this.initObs();
}
initObs() {
this.initStoreObs();
this.initTimelineObs();
}
initStoreObs() {
this.location$ = this.store$.select(s => s.location).pipe(delay(0));
this.date$ = this.store$.select(s => s.date).pipe(delay(0));
}
initTimelineObs() {
this.timeline$ = combineLatest(
this.location$,
this.date$,
(geocode, date) => {
if (!!geocode && !!date) {
return timeline.map(t => new Forecast(geocode, moment(date).add(t.d, 'days'), t.weather));
}
return [];
}
this.timeline$ = this.store$.pipe(
select(selectForecasts),
);
}
}
9 changes: 5 additions & 4 deletions applications/home/src/app/forecast/forecast.module.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { LocationStoreModule, DateStoreModule } from '@meteo/store';
import { ForecastStoreModule } from '@meteo/store';
import { ConductorModule } from '@lucca-front-sdk/ng/ngrx';

import {
ForecastComponent,
ForecastDetailComponent,
TimelineComponent,
TimelineForecastComponent,
} from './components';
import { ForecastMetaModule } from './components/meta/forecast-meta.module';
import { ForecastMetaModule } from './meta/index';


@NgModule({
Expand All @@ -27,9 +28,9 @@ import { ForecastMetaModule } from './components/meta/forecast-meta.module';
],
imports: [
CommonModule,
LocationStoreModule,
DateStoreModule,
ForecastStoreModule,
ForecastMetaModule,
ConductorModule,
],
})
export class ForecastModule { }
2 changes: 2 additions & 0 deletions applications/home/src/app/forecast/meta/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './forecast-meta.component';
export * from './forecast-meta.module';
14 changes: 11 additions & 3 deletions applications/home/src/app/form/components/form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import * as moment from 'moment';
import { Store } from '@ngrx/store';
import { Form, NgForm } from '@angular/forms';

import { IGmapGeocode, IForecast, Forecast } from '@meteo/models';
import { IGmapGeocode } from '@meteo/models';
import { GmapService } from '@meteo/core';
import { SetAdressCmd, SetDateCmd, ILocationStore, IDateStore } from '@meteo/store';
import { Conductor } from '@lucca-front-sdk/ng/ngrx';

@Component({
selector: 'mf-form',
Expand All @@ -32,6 +33,7 @@ export class MfFormComponent implements OnInit, OnDestroy {
constructor(
private gmapService: GmapService,
private store$: Store<ILocationStore & IDateStore>,
private conductor: Conductor,
) {}

ngOnInit() {
Expand All @@ -45,8 +47,14 @@ export class MfFormComponent implements OnInit, OnDestroy {
}
submit() {
if (this.form.valid) {
this.store$.dispatch(new SetAdressCmd(this.model.address));
this.store$.dispatch(new SetDateCmd(this.model.date));
this.conductor.dispatch(new SetAdressCmd(this.model.address))
.subscribe(c => {
console.log(`${c.correlationId} - ${c.type}`);
});
this.conductor.dispatch(new SetDateCmd(this.model.date))
.subscribe(c => {
console.log(`${c.correlationId} - ${c.type}`);
});
}
}
searchAddresses(clue = '') {
Expand Down
2 changes: 2 additions & 0 deletions applications/home/src/app/form/form.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { LocationStoreModule, DateStoreModule } from '@meteo/store';
import {
MfFormComponent,
} from './components';
import { ConductorModule } from '@lucca-front-sdk/ng/ngrx';


@NgModule({
Expand All @@ -28,6 +29,7 @@ import {
LocationStoreModule,
DateStoreModule,
GmapModule,
ConductorModule,
],
providers: [
],
Expand Down
65 changes: 34 additions & 31 deletions applications/home/src/app/router/router.trigger.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
import { Injectable } from '@angular/core';
import { merge } from 'rxjs';
import { merge, of } from 'rxjs';
import { debounceTime, withLatestFrom, tap, map } from 'rxjs/operators';
import { MfActions, AAction, AEvent } from '@meteo/core';
import { IGmapGeocode } from '@meteo/models';
import { Moment } from 'moment';
import { SetDateEvt, SetGeocodeEvt, ILocationStore, IDateStore } from '@meteo/store';
import { Router, ActivatedRoute } from '@angular/router';
import { Store } from '@ngrx/store';
import { Effect } from '@ngrx/effects';
import { Effect, Actions } from '@ngrx/effects';
import { ofPending, ofSuccess, AEvent, ACommand, callAndFollow, correlated, ofComplete, complete, IAction } from '@lucca-front-sdk/ng/ngrx';

class UpdateUrlAction extends AAction<void> {
constructor(location?: IGmapGeocode, date?: Moment) {
super(
'[norm] update url',
undefined,
{ location: location, date: date }
);
}
class UpdateUrlCmd extends ACommand<{ location: IGmapGeocode, date: Moment, }> {
static TYPE = '[cmd] update url';
}
class UpdateUrlEvt extends AEvent<void> {
constructor() {
super('[evt] update url');
}

class UpdateUrlEvt extends AEvent<{ location: IGmapGeocode, date: Moment, }> {
static TYPE = '[evt] update url';
}
@Injectable()
export class RouterTrigger {
locUpdated = this.actions$.of(new SetGeocodeEvt());
dateUpdated = this.actions$.of(new SetDateEvt());
locUpdated = this.actions$.pipe(
ofSuccess(SetGeocodeEvt)
);
dateUpdated = this.actions$.pipe(
ofSuccess(SetDateEvt),
);

updateUrlTrigger = merge(
this.locUpdated,
this.dateUpdated,
).pipe(
debounceTime(500),
withLatestFrom(this.store$.select(s => s.location), this.store$.select(s => s.date)),
tap(x => console.log(x))
);

@Effect() updateUrlHandler = this.updateUrlTrigger
.pipe(map(([action, location, date]) => new UpdateUrlAction(location, date)));
@Effect() trigger = this.updateUrlTrigger
.pipe(map(([action, location, date]) => new UpdateUrlCmd({location: location, date: date})));

@Effect() updateUrlEvt = this.actions$.of(new UpdateUrlAction())
.pipe(
tap(a => {
const params = {
date: a.payload.date.format('YYYY-MM-DD'),
place: a.payload.location.place_id,
};
this.router.navigate([], { queryParams: params, replaceUrl: true, relativeTo: this.route });
}),
map(a => new UpdateUrlEvt()),
);
@Effect() handler = this.actions$.pipe(
ofPending(UpdateUrlCmd),
callAndFollow(p => {
const params = {
date: p.date.format('YYYY-MM-DD'),
place: p.location.place_id,
};
this.router.navigate([], { queryParams: params, replaceUrl: true, relativeTo: this.route });
return of(p);
}, UpdateUrlEvt),
);

@Effect() complete = this.actions$.pipe(
correlated(UpdateUrlCmd),
ofComplete(UpdateUrlEvt),
complete(UpdateUrlCmd),
);
constructor(
private actions$: MfActions,
private actions$: Actions<IAction>,
private router: Router,
private route: ActivatedRoute,
private store$: Store<ILocationStore & IDateStore>,
Expand Down
10 changes: 5 additions & 5 deletions applications/home/src/theming/_commons.override.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ $commons: (
// "size": 14px
// ),
"elevations": (
"1": "0 1px 3px #{rgba($global-shadow-color, 0.12)}, 0 1px 2px #{rgba($global-shadow-color, 0.12)}",
"2": "0 3px 6px #{rgba($global-shadow-color, 0.16)}, 0 3px 6px #{rgba($global-shadow-color, 0.16)}",
"3": "0 10px 20px #{rgba($global-shadow-color, 0.19)}, 0 6px 6px #{rgba($global-shadow-color, 0.23)}",
"4": "0 1px 2px #{rgba($global-shadow-color, 0.05)}, 0 2px 20px #{rgba($global-shadow-color, 0.2)}",
"5": "0 2px 4px #{rgba($global-shadow-color, 0.05)}, 0 4px 40px #{rgba($global-shadow-color, 0.2)}"
"elevation-1": "0 1px 3px #{rgba($global-shadow-color, 0.12)}, 0 1px 2px #{rgba($global-shadow-color, 0.12)}",
"elevation-2": "0 3px 6px #{rgba($global-shadow-color, 0.16)}, 0 3px 6px #{rgba($global-shadow-color, 0.16)}",
"elevation-3": "0 10px 20px #{rgba($global-shadow-color, 0.19)}, 0 6px 6px #{rgba($global-shadow-color, 0.23)}",
"elevation-4": "0 1px 2px #{rgba($global-shadow-color, 0.05)}, 0 2px 20px #{rgba($global-shadow-color, 0.2)}",
"elevation-5": "0 2px 4px #{rgba($global-shadow-color, 0.05)}, 0 4px 40px #{rgba($global-shadow-color, 0.2)}"
),
// "border": (
// "radius": 2px
Expand Down
1 change: 0 additions & 1 deletion libraries/core/src/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from './store/index';
export * from './gmap/index';
export * from './locale/index';
Loading