當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript store-saga.createSaga函數代碼示例

本文整理匯總了TypeScript中store-saga.createSaga函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript createSaga函數的具體用法?TypeScript createSaga怎麽用?TypeScript createSaga使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了createSaga函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: createSaga

import {Http} from '@angular/http';
import {Router} from '@angular/router-deprecated';
import {Observable} from 'rxjs';
import {createSaga} from 'store-saga';
import {INCREMENT, DECREMENT, GOTO_ABOUT} from './../actions';

const BASE_WEB_URL = 'http://jsonplaceholder.typicode.com/';

const increment = createSaga(function() {
  return iteration$ => iteration$
    .filter(iter => iter.action.type === DECREMENT)
    .map(() => {
      return { type: INCREMENT };
    });
});

const remoteMethod = () => new Promise((res, rej) => {
  setTimeout(() => res(20), 1000);
});

const asyncEffect = createSaga(function sagaFactory(http: Http) {

  return function loginSaga(iteration$: Observable<any>) {
    return iteration$
      .filter(iteration => iteration.action.type === DECREMENT)
      .map(iteration => iteration.action.payload)
      .mergeMap(payload => {
        return Observable.fromPromise(remoteMethod())
          .map(res => {
            return {
              type: INCREMENT
開發者ID:ksachdeva,項目名稱:angular2-store-saga-example,代碼行數:31,代碼來源:index.ts

示例2: Schema

  PATCH_PERSON_SUCCESS,
  PATCH_PERSON_FAIL,
  ADD_PERSON_REQUEST,
  ADD_PERSON_SUCCESS,
  ADD_PERSON_FAIL
} from '../reducers/people.reducer';

export const peopleSchema = new Schema('people');

const list = createSaga((_appHttp: AppHttp): Saga<any> => {
  return saga$ => saga$
    .filter(whenAction(LOAD_PEOPLE_REQUEST))
    .mergeMap(
      saga$ => _appHttp
        .get('http://localhost:3100'+ getUrlWithIds('people', saga$.action.payload)),
      (saga$, payload) => generateResponse(
        payload,
        LOAD_PEOPLE_SUCCESS,
        LOAD_PEOPLE_FAIL,
        (res) => normalize(res, arrayOf(peopleSchema))
      )
    );
}, [ AppHttp ]);

const one = createSaga((_appHttp: AppHttp): Saga<any> => {
  return saga$ => saga$
    .filter(whenAction(LOAD_PERSON_REQUEST))
    .let(shouldLoad('people', 'payload'))
    .mergeMap(
      saga$ => _appHttp
        .get(`http://localhost:3100/people/${saga$.action.payload}`),
      (saga$, payload) => generateResponse(
開發者ID:Lukinos,項目名稱:ngrx-example,代碼行數:32,代碼來源:people.sagas.ts

示例3: createSaga

  LOGIN_FAIL,
  LOG_OUT_REQUEST,
  LOG_OUT_SUCCESS
} from '../reducers/auth.reducer';

const login = createSaga((_http: AppHttp): Saga<any> => {
  return saga$ => saga$
    .filter(whenAction(LOGIN_REQUEST))
    .delay(1)
    .mergeMap(
      saga$ => _http.post(
        'http://localhost:3100/login',
        JSON.stringify(saga$.action.payload)
      ),
      (saga$, payload) => generateResponse(
        payload,
        LOGIN_SUCCESS,
        LOGIN_FAIL,
        (res) => {
          localStorage.setItem('auth', JSON.stringify(res));

          return res;
        }
      )
    );
}, [ AppHttp ]);

const logout = createSaga((): Saga<any> => {
  return saga$ => saga$
    .filter(whenAction(LOG_OUT_REQUEST))
    .delay(1)
開發者ID:mckennatim,項目名稱:ngrx-example,代碼行數:31,代碼來源:auth.sagas.ts

示例4: createSaga

].map(effect => createSaga(effect));
開發者ID:willSonic,項目名稱:ngrx-examples,代碼行數:1,代碼來源:shop.ts

示例5: createSaga

  ADD_NOTIFICATION,
  START_NOTIFICATIONS,
  STOP_NOTIFICATIONS
} from '../reducers/notifications.reducer';

const add = createSaga((_store: Store<any>) => {
  return saga$ => saga$
    .filter(whenAction(START_NOTIFICATIONS))
    .delay(1)
    .mergeMap(authData => Observable
      .webSocket(`ws://localhost:3200`)
      .retryWhen((res) => {
        return res.delay(5000);
      })
      .takeUntil(saga$.filter(whenAction(STOP_NOTIFICATIONS)))
    )
    .catch(res => {
      return Observable.of(false);
    })
    .filter((res) => {
      return !!res
    })
    .map(res => ({
      type: ADD_NOTIFICATION,
      payload: res
    }));
}, [ Store ]);

export const notificationsSagas = [
  add
];
開發者ID:Lukinos,項目名稱:ngrx-example,代碼行數:31,代碼來源:notifications.sagas.ts

示例6: createSaga

import {Observable} from 'rxjs/Observable';

export const loginRequest = createSaga((http:Http)=>{
   return saga$=>saga$.filter(whenAction('LOGIN_REQUEST'))
   .do(e=>{console.log('login request ',e);
e.state.loading=true;
})
   //.delay(1000)
   .flatMap((saga)=>{
       console.log(saga);
        var data={username:saga.action.payload.username,password:saga.action.payload.password};
        console.log(saga.state);
       const query=http.post('http://virtual2.ballistix.co.uk:8000/api/token',JSON.stringify(data));
  
        return query.map(e=>e.json());
   })
   .map( res => {
     console.log(res);
     if (res.status==200){
         localStorage.setItem('token',res.token);
         return {type:'LOGIN_COMPLETE',payload:res.token};
     }
   })
   .catch(error => {
       console.log('error');
       return Observable.of(false);
   }
    )
   
},[Http]);

export const increment = createSaga((http:Http)=>{
開發者ID:JamesUlph,項目名稱:ng2-start,代碼行數:32,代碼來源:sagas.ts

示例7: createSaga

import {FETCH, UPDATE, DETAIL, UPDATE_SELECTED} from './../reducers/repos';

const BASE_WEB_URL = 'https://api.github.com/';

const fetchEffect = createSaga(function sagaFactory(http: Http) {
  return function fetchSaga(iteration$: Observable<any>) {
    return iteration$
      .filter(iteration => iteration.action.type === FETCH)
      .map(iteration => iteration.action.payload)
      .mergeMap(payload => {
        return http.get(BASE_WEB_URL + 'orgs/' + payload + '/repos')
          .map(res => {
            return {
              type: UPDATE,
              payload: res.json()
            }
          })
          .catch(err => {
            return Observable.of({
              type: UPDATE,
              payload: []
            });
          });
      });
  };

}, [Http]);

const fetchSingleEffect = createSaga(function sagaFactory(http: Http) {
  return function fetchSingleSaga(iteration$: Observable<any>) {
    return iteration$
開發者ID:Lube,項目名稱:angular2-seed,代碼行數:31,代碼來源:repos.ts

示例8: createSaga

import { Provider } from '@angular/core';
import { createSaga, toPayload, whenAction } from 'store-saga';
import { ApiService } from 'src/core/api';
import * as actions from './action-creators';
import * as types from './action-types';


//=====================================
//  SAGAS
//-------------------------------------

export const createTask = createSaga((api: ApiService) => {
  return saga$ => saga$
    .filter(whenAction(types.CREATE_TASK))
    .map(toPayload)
    .switchMap(payload => api
      .createTask(payload.task)
      .map(task => actions.createTaskSuccess(task)));
}, [ApiService]);


export const deleteTask = createSaga((api: ApiService) => {
  return saga$ => saga$
    .filter(whenAction(types.DELETE_TASK))
    .map(toPayload)
    .switchMap(payload => api
      .deleteTask(payload.taskId)
      .map(task => actions.deleteTaskSuccess(task)));
}, [ApiService]);

開發者ID:willSonic,項目名稱:todo-angular2-ngrx,代碼行數:29,代碼來源:sagas.ts

示例9: createSaga

import {ADD_AUDIOITEM_TO_PLAYLIST, UPDATE_AUDIOITEM_IN_PLAYLIST} from '../reducers/playlistReducer';
import {IAudiodata} from '../reducers/audioReducer';
import {PLAY_INITIATED, PLAY_START, PLAY_STOP, TOGGLE_PLAY_PAUSE} from '../reducers/audioplayerReducer';
import  * as ArtistAPI from  '../../api/artistAPI';
import  * as DataLoadAPI  from  '../../api/dataloadAPI';
import { WebAudioPlayerAPI } from '../../api/webaudioAPI';
import { Observable } from 'rxjs/Observable';



const artistFetch = createSaga( function(){
    return iteration$ => iteration$
         .filter(whenAction(REQUEST_ARTISTS))
         .mergeMap(()  => ArtistAPI.default.getArtists(300))
         .map(res => {
                return {
                    type: RECEIVED_ARTISTS,
                    payload: res
               };
         });
});


const createPlayListItem = createSaga( function sagaFactory() {
        return function someService(iteration$: Observable<any>) {
    return iteration$ .filter(whenAction(CREATE_AUDIODATA))
        .mergeMap((iteration) => {
            if(iteration.state.audioItem){
                 var trackURL = Object.keys(iteration.state.artists)
                                        .filter( x =>  {
                                               return iteration.state.artists[x].id  ===  iteration.state.audioItem.artistId})
開發者ID:willSonic,項目名稱:angular2-exp-ngrx,代碼行數:31,代碼來源:audiomachine.ts


注:本文中的store-saga.createSaga函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。