示例#1
0
export default function redirects( state = {}, action ) {
	switch ( action.type ) {
		case REDIRECT_ADD_TOP:
			return { ... state, addTop: action.onoff };

		case REDIRECT_LOADING:
			return { ... state, table: setTable( state, action ), status: STATUS_IN_PROGRESS, saving: [] };

		case REDIRECT_LOADED:
			return { ... state, rows: setRows( state, action ), status: STATUS_COMPLETE, total: setTotal( state, action ), table: clearSelected( state.table ) };

		case REDIRECT_ITEM_SAVING:
			return { ... state, table: clearSelected( setTable( state, action ) ), saving: setSaving( state, action ), rows: setItem( state, action ) };

		case REDIRECT_ITEM_SAVED:
			return { ... state, rows: setRows( state, action ), total: setTotal( state, action ), saving: removeSaving( state, action ) };

		case REDIRECT_SET_ALL_SELECTED:
			return { ... state, table: setTableAllSelected( state.table, state.rows, action.onoff ) };

		case REDIRECT_SET_SELECTED:
			return { ... state, table: setTableSelected( state.table, action.items ) };

		case REDIRECT_FAILED:
			return { ... state, status: STATUS_FAILED, saving: [] };

		case REDIRECT_ITEM_FAILED:
			return { ... state, saving: removeSaving( state, action ), rows: restoreToOriginal( state, action ) };
	}

	return state;
}
示例#2
0
	test( 'setTotal returns new total', () => {
		expect( setTotal( { total: 1 }, { total: 3 } ) ).toEqual( 3 );
	} );
示例#3
0
	test( 'setTotal returns existing total if non provided', () => {
		expect( setTotal( { total: 1 }, {} ) ).toEqual( 1 );
	} );