Skip to content

Commit

Permalink
minor reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshpai committed Jul 27, 2017
1 parent 7917ef8 commit 845bff2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/reducers/index.js
@@ -1,6 +1,6 @@
import { combineReducers } from 'redux';
import { routerReducer as router } from 'react-router-redux';
import migrate from './migrations';
import { migrateReducer } from './migrations';
import networks from './networks';

//import validate from '../lib/validate-network';
Expand All @@ -12,7 +12,7 @@ const combined = combineReducers({
});

export default (state, action) => {
const migrated = migrate(state, action);
const migrated = migrateReducer(state, action);
const newState = combined(migrated, action);
//console.log('Network validation errors:', validate(newState.networks[0]));
return newState;
Expand Down
24 changes: 13 additions & 11 deletions src/reducers/migrations.js
Expand Up @@ -2,20 +2,22 @@ const migrations = [
network => network, // Need this for seeding
];

export default (state, action) => {
if(action.type !== 'MIGRATE') return state;
export const migrate = network => {
const migrationsToApply = migrations.slice(network.version || 0);

if(migrationsToApply.length) console.log(`Migrating network ${network.id}...`);

return {
...state,
networks: state.networks.map(network => {
const migrationsToApply = migrations.slice(network.version || 0);
...migrationsToApply.reduce((network, migrate) => migrate(network), network),
version: migrations.length
}
}

if(migrationsToApply.length) console.log(`Migrating network ${network.id}...`);
export const migrateReducer = (state, action) => {
if(action.type !== 'MIGRATE') return state;

return {
...migrationsToApply.reduce((network, migrate) => migrate(network), network),
version: migrations.length
}
})
return {
...state,
networks: state.networks.map(migrate)
}
}

0 comments on commit 845bff2

Please sign in to comment.