p5.js-web-editor/client/modules/IDE/reducers/files.js

51 lines
1 KiB
JavaScript
Raw Normal View History

2016-06-22 19:58:23 +00:00
import * as ActionTypes from '../../../constants';
2016-05-05 21:48:26 +00:00
const initialState = {
2016-06-23 22:29:55 +00:00
name: 'sketch.js',
content: `function setup() {
createCanvas(400, 400);
2016-05-09 22:28:38 +00:00
}
function draw() {
2016-06-23 22:29:55 +00:00
background(220);
2016-05-09 22:28:38 +00:00
}`
2016-06-23 22:29:55 +00:00
};
2016-05-05 21:48:26 +00:00
const file = (state = initialState, action) => {
2016-06-23 22:29:55 +00:00
switch (action.type) {
case ActionTypes.CHANGE_SELECTED_FILE:
return {
name: action.name,
content: action.content
};
case ActionTypes.NEW_PROJECT:
return {
name: action.file.name,
2016-06-29 16:52:16 +00:00
content: action.file.content
};
case ActionTypes.SET_PROJECT:
return {
name: action.file.name,
content: action.file.content
2016-06-23 22:29:55 +00:00
};
default:
return state;
}
};
2016-05-05 21:48:26 +00:00
export default file;
2016-06-23 22:29:55 +00:00
// i'll add this in when there are multiple files
2016-05-05 21:48:26 +00:00
// const files = (state = [], action) => {
2016-06-23 22:29:55 +00:00
// switch (action.type) {
// case ActionTypes.CHANGE_SELECTED_FILE:
// //find the file with the name
// //update it
// //put in into the new array of files
// default:
// return state
// }
2016-05-05 21:48:26 +00:00
// }
2016-06-23 22:29:55 +00:00
// export default files