2016-02-05 22:25:17 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @providesModule NavigationFindReducer
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NavigationFindReducer takes an array of reducers, and returns a reducer that
|
|
|
|
* iterates through all of the reducers and the result of the first reducer
|
|
|
|
* that modifies the input
|
|
|
|
*/
|
|
|
|
|
|
|
|
import type {
|
|
|
|
NavigationState,
|
|
|
|
NavigationReducer
|
2016-03-04 22:56:37 +00:00
|
|
|
} from 'NavigationTypeDefinition';
|
2016-02-05 22:25:17 +00:00
|
|
|
|
2016-03-04 22:56:37 +00:00
|
|
|
function NavigationFindReducer(
|
|
|
|
reducers: Array<NavigationReducer>,
|
|
|
|
defaultState: NavigationState,
|
|
|
|
): NavigationReducer {
|
2016-02-23 00:15:35 +00:00
|
|
|
return function(lastState: ?NavigationState, action: ?any): NavigationState {
|
2016-02-05 22:25:17 +00:00
|
|
|
for (let i = 0; i < reducers.length; i++) {
|
|
|
|
let reducer = reducers[i];
|
|
|
|
let newState = reducer(lastState, action);
|
|
|
|
if (newState !== lastState) {
|
2016-02-23 00:15:35 +00:00
|
|
|
return newState || defaultState;
|
2016-02-05 22:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-23 00:15:35 +00:00
|
|
|
return lastState || defaultState;
|
2016-02-05 22:25:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = NavigationFindReducer;
|