Skip to content

Commit

Permalink
fix: add take(1) to backend observables
Browse files Browse the repository at this point in the history
  • Loading branch information
petrot committed Apr 16, 2018
1 parent c8dc8e8 commit dbe62e9
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class HikeProgramService {
.getRecord<IHikeProgramStored>(`hike_programs/${id}`)
.get()
.filter(data => data.stops instanceof Array)
.take(1)
.map(data => {
let hike: HikeProgram = new HikeProgram(data, this._checkpointService);

Expand All @@ -32,6 +33,7 @@ export class HikeProgramService {
table: 'hike_programs',
query: []
})
.take(1)
.map(data => {
return data.filter(item => item.stops instanceof Array).map(item => {
let hike: HikeProgram = new HikeProgram(item, this._checkpointService);
Expand All @@ -48,6 +50,8 @@ export class HikeProgramService {
data = hikeProgram.toObject();
}

return this._deepstream.callRpc<IHikeProgramSaveResponse>('admin.hike-program.save', data);
return this._deepstream
.callRpc<IHikeProgramSaveResponse>('admin.hike-program.save', data)
.take(1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class PoiService {
return this._deepstream
.getRecord<IPoiStored>(`pois/${id}`)
.get()
.take(1)
.map(data => {
return _.cloneDeep(data);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class RouteService {
return this._deepstream
.getRecord<IRouteStored>(`routes/${id}`)
.get()
.take(1)
.map(data => {
if (!data.id) {
return null;
Expand Down
4 changes: 4 additions & 0 deletions src/subrepos/gtrack-common-ngx/app/hike/store/hike/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class HikeEffects {
.mergeMap(action => {
return this._hikeProgramService
.get(action.context)
.take(1)
.map(hike => {
if (hike !== null) {
return new LocalActions.HikeProgramLoaded(action.context, hike);
Expand All @@ -36,8 +37,10 @@ export class HikeEffects {
.mergeMap(action => {
return this._hikeProgramService
.query()
.take(1)
.map(hikePrograms => {
let ids = hikePrograms.map(hikeProgram => hikeProgram.id);

return new LocalActions.AllHikeProgramsLoaded(ids, hikePrograms);
});
});
Expand All @@ -48,6 +51,7 @@ export class HikeEffects {
.mergeMap(action => {
return this._hikeProgramService
.create(action.hikeProgram)
.take(1)
.map(response => new LocalActions.HikeProgramSaved(response.id));
});

Expand Down
3 changes: 3 additions & 0 deletions src/subrepos/gtrack-common-ngx/app/hike/store/poi/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class PoiEffects {
.mergeMap(action => {
return this._poiService
.get(action.context)
.take(1)
.map(poi => {
return new LocalActions.PoiLoaded(action.context, poi);
});
Expand All @@ -29,6 +30,7 @@ export class PoiEffects {
return this._poiService
.get(context);
}))
.take(1)
.map(pois => {
return new LocalActions.AllPoiLoaded(action.contexts, pois);
});
Expand All @@ -40,6 +42,7 @@ export class PoiEffects {
.mergeMap(action => {
return this._poiService
.create(action.poi)
.take(1)
.map(response => new LocalActions.PoiSaved(response.id));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class RouteEffects {
.mergeMap(action => {
return this._routeService
.get(action.context)
.take(1)
.map(route => {
if (route !== null) {
return new LocalActions.RouteLoaded(action.context, route);
Expand All @@ -33,6 +34,7 @@ export class RouteEffects {
.mergeMap(action => {
return this._routeService
.create(action.route)
.take(1)
.map(response => new LocalActions.RouteSaved(response.id));
});

Expand Down

0 comments on commit dbe62e9

Please sign in to comment.