2017-11-13 21 views
0

最後の要素が更新されるときに間隔を停止しようとしています。最後の要素が更新されるときの間隔をクリアする

私は方法がわかりません。私はトラックで始めることができますか?

現時点では、ページを離れるときに私の間隔をクリアします。

this.subscriptions.push(this.requestId.subscribe(id => { 
     this.store.dispatch(new requestActions.LoadRequest(id)); 
     this.interval = setInterval(() => { 
      this.store.dispatch(new requestActions.LoadRequest(id)); 
     }, 1700); 
    })); 

マイ効果:

@Effect() 
loadRequest$: Observable<Action> = this.actions$ 
    .ofType<requestActions.LoadRequest>(requestActions.LOAD_REQUEST) 
    .switchMap(action => { 
     return this.apiService 
      .loadRequest(action.payload) 
      .map((task: RequestTask[]) => new requestActions.LoadRequestSuccessAction(task)) 
      .catch(error => of(new requestActions.LoadRequestFailureAction(error))); 
    }); 

私の減速:

case request.LOAD_REQUEST_SUCCESS: 
     console.log("Payload : ", action.payload); 
     return { 
      ...adapter.addAll(action.payload, state), 
      loaded: true, 
      selectedIndex: null 
     } as State; 
+0

私はあなたが正直に達成しようとしているものを得ることはありません。あなたはもっと明確になりますか? – AndreaM16

答えて

0

私はこれを行うことによって、私の問題を解決するために管理しました}

そして最後に、私は「クリア」私の間隔は、戻り値がfalseである

refresh: boolean; 

this.subscriptions.push(this.requestId.subscribe(id => { 
     this.store.dispatch(new requestActions.LoadEvents(id)); 
     this.interval = setInterval(() => { 
      this.store.dispatch(new requestActions.LoadEvents(id)); 
      this.store.select(fromRoot.getRefreshEntitiesState).subscribe(data => this.refresh = data) 
      console.log("Refresh :", this.refresh) 
      if (this.refresh != undefined && this.refresh === false) { 
       clearInterval(this.interval); 
      } 
     }, 1700); 
    })) 
0

errorcomplete状態を追加します。

export function reducer(state: State = initialState, action: request.Actions): State { 
switch (action.type) { 
    case request.LOAD_EVENTS_SUCCESS: 
     console.log("Payload events : ", action.payload); 
     const status = getStatusOfEvents(action.payload) 
     return { 
      ...adapter.addAll(action.payload, state), 
      refresh: status, 
      loaded: true, 
     } as State; 
    case request.LOAD_EVENTS: 
    case request.LOAD_EVENTS_FAILURE: 
    default: 
     return state; 
} 

:私は

function getStatusOfEvents(payload : any){ 
const object = payload as Event[] 
const events = object.map(obj => obj.status); 

if (events.includes("PENDING")){ 
    return true; 
} else { 
    return false; 
} } 

は、私が店に値を配置する関数を作成

export interface State extends EntityState<Event> { 
request: Request } 

this.subscriptions.push(this.requestId.subscribe(id => { 
    this.store.dispatch(new requestActions.LoadRequest(id)); 
    this.interval = setInterval(() => { 
     this.store.dispatch(new requestActions.LoadRequest(id)); 
    }, 1700); 
}),(err)=>{console.log(err);}, 
()=>{ 
    clearInterval(this.interval); 
} 
); 
+0

今日はやっています。どうも –

関連する問題