feat setup: Setup Redux, Immutable.js and React
feat FileList: Implement File List + changedir action
This commit is contained in:
10
src/js/reducers/all.js
Normal file
10
src/js/reducers/all.js
Normal file
@ -0,0 +1,10 @@
|
||||
import Immutable from 'immutable';
|
||||
import cwd from './cwd';
|
||||
import files from './files';
|
||||
|
||||
export default function(state = new Immutable.Map(), action) {
|
||||
return new Immutable.Map({
|
||||
cwd: cwd(state.get('cwd'), action),
|
||||
files: files(state.get('files'), action)
|
||||
});
|
||||
}
|
16
src/js/reducers/cwd.js
Normal file
16
src/js/reducers/cwd.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { CHANGE_DIRECTORY } from 'actions/types';
|
||||
import listFiles from 'actions/list-files';
|
||||
import { children } from 'api/files';
|
||||
import store from 'store';
|
||||
|
||||
export default function(state = '/', action) {
|
||||
switch (action.type) {
|
||||
case CHANGE_DIRECTORY:
|
||||
children(action.dir).then(files => {
|
||||
store.dispatch(listFiles(files));
|
||||
});
|
||||
return action.dir;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
10
src/js/reducers/files.js
Normal file
10
src/js/reducers/files.js
Normal file
@ -0,0 +1,10 @@
|
||||
import { LIST_FILES } from 'actions/types';
|
||||
|
||||
export default function(state = [], action) {
|
||||
switch (action.type) {
|
||||
case LIST_FILES:
|
||||
return action.files;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user