-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
redux: moved fetched rows under store.watches.data[watchIndex] (#6)
- Loading branch information
Showing
13 changed files
with
99 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
import { combineReducers} from 'redux' | ||
import data from './data' | ||
import watches from './watches' | ||
import synctimes from './synctimes' | ||
import config from './config' | ||
import versions from './versions' | ||
import fetchStatus from './fetchStatus' | ||
import captorPredicatesUpdater from './captorPredicatesUpdater' | ||
import view from './view' | ||
import _ from 'lodash' | ||
|
||
const combinedReducers = combineReducers({ | ||
data, | ||
const combinedReducers = combineReducersWithState({ | ||
view, | ||
watches, | ||
fetchStatus, | ||
synctimes, | ||
config, | ||
versions, | ||
view, | ||
}) | ||
|
||
function kibanatorApp(state, action) { | ||
const intermediateState = combinedReducers(state, action); | ||
return captorPredicatesUpdater(intermediateState, action) | ||
return combinedReducers(state, action); | ||
} | ||
|
||
function combineReducersWithState(combination) { | ||
return (state, action) => { | ||
return _.mapValues(combination, (reducer, key)=> reducer(state[key], action, state)) | ||
} | ||
} | ||
|
||
export default kibanatorApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import data from './data' | ||
import _ from 'lodash' | ||
|
||
const startingState = { | ||
data: {} | ||
} | ||
|
||
export default function watches (state = startingState, action, fullState) { | ||
|
||
if (action.type === 'RESET_DATA') { | ||
return startingState | ||
} | ||
|
||
//delegate the rest to the specific data reducer if watchIndex present | ||
let watchIndex = _.get(action, 'payload.watchIndex') | ||
|
||
if (undefined === watchIndex) { | ||
watchIndex = _.get(fullState, 'view.watchIndex') | ||
} | ||
|
||
if (undefined === watchIndex) { | ||
return startingState | ||
} | ||
|
||
watchIndex = "" + watchIndex //stringify index | ||
|
||
let filters = _.get(fullState.config.watches[watchIndex], 'captors') | ||
|
||
let updatedData = data(state.data[watchIndex], action, filters) | ||
|
||
if (undefined === updatedData) { | ||
console.warn('unexpectedly undefined data for watch index', watchIndex) | ||
} | ||
|
||
return {...state, data: { | ||
...state.data, | ||
[watchIndex]: updatedData | ||
}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import {emptyState} from '../reducers/data' | ||
export function selectedData(state, fallbackEmptyState) { | ||
const watchIndex = state.view.watchIndex | ||
if (undefined !== watchIndex) { | ||
let theData = state.watches.data[watchIndex + ""] | ||
if (undefined !== theData) { | ||
return theData | ||
} | ||
} | ||
if (fallbackEmptyState) { | ||
return emptyState | ||
} else { | ||
return undefined | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters