2016-06-22 19:58:23 +00:00
|
|
|
import * as ActionTypes from '../../../constants';
|
2016-05-05 21:48:26 +00:00
|
|
|
|
2016-07-06 19:09:05 +00:00
|
|
|
const defaultSketch = `function setup() {
|
2016-06-23 22:29:55 +00:00
|
|
|
createCanvas(400, 400);
|
2016-05-09 22:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function draw() {
|
2016-06-23 22:29:55 +00:00
|
|
|
background(220);
|
2016-07-06 19:09:05 +00:00
|
|
|
}`;
|
|
|
|
|
|
|
|
const defaultHTML =
|
|
|
|
`
|
|
|
|
<!DOCTYPE html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script src="sketch.js"></script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
`;
|
|
|
|
|
|
|
|
const initialState = [
|
|
|
|
{
|
|
|
|
name: 'sketch.js',
|
|
|
|
content: defaultSketch
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'index.html',
|
|
|
|
content: defaultHTML
|
|
|
|
}];
|
2016-05-05 21:48:26 +00:00
|
|
|
|
2016-07-06 19:09:05 +00:00
|
|
|
|
|
|
|
const files = (state = initialState, action) => {
|
2016-06-23 22:29:55 +00:00
|
|
|
switch (action.type) {
|
2016-07-07 17:50:52 +00:00
|
|
|
case ActionTypes.UPDATE_FILE_CONTENT:
|
2016-07-06 19:09:05 +00:00
|
|
|
return state.map(file => {
|
|
|
|
if (file.name !== action.name) {
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2016-07-07 17:50:52 +00:00
|
|
|
return Object.assign({}, file, { content: action.content });
|
2016-07-06 19:09:05 +00:00
|
|
|
});
|
2016-06-23 22:29:55 +00:00
|
|
|
case ActionTypes.NEW_PROJECT:
|
2016-07-06 21:29:07 +00:00
|
|
|
return [...action.files];
|
2016-06-29 16:52:16 +00:00
|
|
|
case ActionTypes.SET_PROJECT:
|
2016-07-06 21:29:07 +00:00
|
|
|
return [...action.files];
|
2016-06-23 22:29:55 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
2016-05-05 21:48:26 +00:00
|
|
|
|
2016-07-06 19:09:05 +00:00
|
|
|
export default files;
|