在 rxjs5 Store 中存储和实例而不是数组
Storing and instance instead of an array in rxjs5 Store
我对减速器有以下尝试
import { ActionReducer, Action, Store } from '@ngrx/store';
import { Observable } from 'rxjs'
import { Name } from './name.model'
export const ADD_NAME = 'ADD_NAME';
export const name: ActionReducer<any> = ( state = new Name(), action: Action ) => {
switch ( action.type ) {
case ADD_NAME:
return [ state, action.payload ];
default:
return state;
}
};
我想在商店中存储一个名称实例。目前ADD_NAMEreturns一个数组。我怎样才能只存储一个实例而不是数组
你可以用 typescript 2.1+ 来写:
case ADD_NAME:
return { ...state, action.payload };
或
case ADD_NAME:
return Object.assign({}, state, action.payload);
我对减速器有以下尝试
import { ActionReducer, Action, Store } from '@ngrx/store';
import { Observable } from 'rxjs'
import { Name } from './name.model'
export const ADD_NAME = 'ADD_NAME';
export const name: ActionReducer<any> = ( state = new Name(), action: Action ) => {
switch ( action.type ) {
case ADD_NAME:
return [ state, action.payload ];
default:
return state;
}
};
我想在商店中存储一个名称实例。目前ADD_NAMEreturns一个数组。我怎样才能只存储一个实例而不是数组
你可以用 typescript 2.1+ 来写:
case ADD_NAME:
return { ...state, action.payload };
或
case ADD_NAME:
return Object.assign({}, state, action.payload);