first Blockly functionalities

Attention: the buttons currently trigger an error
This commit is contained in:
Delucse
2020-07-23 11:33:13 +02:00
parent 857da78c49
commit c05572a68e
15 changed files with 766 additions and 25 deletions
+5
View File
@@ -0,0 +1,5 @@
export const NEW_WORKSPACE = 'NEW_WORKSPACE';
export const CREATE_BLOCK = 'CREATE_BLOCK';
export const CHANGE_BLOCK = 'CHANGE_BLOCK';
export const DELETE_BLOCK = 'DELETE_BLOCK';
export const CLEAR_STATS = 'CLEAR_STATS';
+53
View File
@@ -0,0 +1,53 @@
import { NEW_WORKSPACE, CREATE_BLOCK, CHANGE_BLOCK, DELETE_BLOCK, CLEAR_STATS } from './types';
export const onChangeWorkspace = (event) => (dispatch, getState) => {
var oldWorkspace = getState().workspace.new; // stored 'new workspace' is from now on old
var newWorkspace = window.Ardublockly.workspace;
dispatch({
type: NEW_WORKSPACE,
payload: {new: newWorkspace, old: oldWorkspace}
});
var stats = getState().workspace.stats;
if (event.type === window.Blockly.Events.CREATE){
stats.create += event.ids.length;
dispatch({
type: CREATE_BLOCK,
payload: stats
});
}
else if (event.type === window.Blockly.Events.CHANGE){
stats.change += 1;
dispatch({
type: CHANGE_BLOCK,
payload: stats
});
}
else if (event.type === window.Blockly.Events.DELETE){
if(stats.create > 0){
stats.delete += event.ids.length;
dispatch({
type: DELETE_BLOCK,
payload: stats
});
}
}
};
export const clearStats = () => (dispatch) => {
var stats = {
create: 0,
change: 0,
delete: 0
};
dispatch({
type: CLEAR_STATS,
payload: stats
});
};
export const setWorkspace = (workspace) => (dispatch, getState) => {
dispatch({
type: NEW_WORKSPACE,
payload: {new: workspace, old: getState().workspace.new}
});
};