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

46 lines
932 B
JavaScript
Raw Normal View History

2016-06-22 21:58:23 +02:00
import * as ActionTypes from '../../../constants';
2016-05-05 23:48:26 +02:00
const initialState = {
2016-06-24 00:29:55 +02:00
name: 'sketch.js',
content: `function setup() {
createCanvas(400, 400);
2016-05-10 00:28:38 +02:00
}
function draw() {
2016-06-24 00:29:55 +02:00
background(220);
2016-05-10 00:28:38 +02:00
}`
2016-06-24 00:29:55 +02:00
};
2016-05-05 23:48:26 +02:00
const file = (state = initialState, action) => {
2016-06-24 00:29:55 +02: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,
content: action.file.conent
};
default:
return state;
}
};
2016-05-05 23:48:26 +02:00
export default file;
2016-06-24 00:29:55 +02:00
// i'll add this in when there are multiple files
2016-05-05 23:48:26 +02:00
// const files = (state = [], action) => {
2016-06-24 00:29:55 +02: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 23:48:26 +02:00
// }
2016-06-24 00:29:55 +02:00
// export default files