diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-06-05 15:40:56 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-06-05 15:40:56 +0200 |
| commit | e243e4f65cc2c98724a1cfb4d28ac5f1d1bc0a79 (patch) | |
| tree | b843eed4b0a39d58b1feeaf9a2f44182867cccf5 /app/client | |
| parent | ba825eb101f8ca1cbf5de7a87c6c2995a0d687a5 (diff) | |
api events over bridge
Diffstat (limited to 'app/client')
| -rw-r--r-- | app/client/modules/samplernn/samplernn.reducer.js | 43 | ||||
| -rw-r--r-- | app/client/socket/index.js | 2 | ||||
| -rw-r--r-- | app/client/socket/socket.api.js | 32 |
3 files changed, 75 insertions, 2 deletions
diff --git a/app/client/modules/samplernn/samplernn.reducer.js b/app/client/modules/samplernn/samplernn.reducer.js index c271407..5255ca3 100644 --- a/app/client/modules/samplernn/samplernn.reducer.js +++ b/app/client/modules/samplernn/samplernn.reducer.js @@ -63,7 +63,19 @@ const samplernnReducer = (state = samplernnInitialState, action) => { if (action.data.module === 'samplernn') { console.log(action.data) let dataset, old_dataset, folder, old_folder - const dataset_name = action.data.name.split('.')[0] + let dataset_name + if (action.data.dataset) { + dataset_name = action.data.dataset + } + else if (action.data.name) { + dataset_name = action.data.name.split('.')[0] + } + else if (action.data.url) { + dataset_name = action.data.url + } + else { + dataset_name = null + } if (dataset_name in state.data.datasetLookup) { old_dataset = state.data.datasetLookup[dataset_name] dataset = { @@ -112,15 +124,42 @@ const samplernnReducer = (state = samplernnInitialState, action) => { case types.file.update: if (action.data.module === 'samplernn') { + let old_dataset; + let new_dataset = state.data.datasetLookup[action.data.dataset] + let old_file = state.data.fileLookup[action.data.id] + let new_dataset_update; + if (old_file && action.data.dataset !== old_file.dataset) { + if (state.data.datasetLookup[old_file.dataset]) { + old_dataset = state.data.datasetLookup[old_file.dataset] + old_dataset_update = { + ...old_dataset, + input: old_dataset.input.filter(id => id !== action.data.id), + output: old_dataset.output.filter(id => id !== action.data.id), + } + } + new_dataset_update = { + ...new_dataset, + input: action.data.generated ? [] : [action.data.id], + output: !action.data.generated ? [] : [action.data.id], + } + } return { ...state, loading: false, data: { ...state.data, + datasetLookup: old_dataset ? { + ...state.data.datasetLookup, + [old_dataset.name]: old_dataset_update, + [new_dataset.name]: new_dataset_update, + } : new_dataset_update ? { + ...state.data.datasetLookup, + [new_dataset.name]: new_dataset_update, + } : state.data.datasetLookup, fileLookup: { ...state.data.fileLookup, [action.data.id]: action.data, - } + }, } } } diff --git a/app/client/socket/index.js b/app/client/socket/index.js index a5d9987..3caab6d 100644 --- a/app/client/socket/index.js +++ b/app/client/socket/index.js @@ -6,6 +6,7 @@ import * as actions from './socket.actions' import * as system from './socket.system' import * as live from './socket.live' import * as task from './socket.task' +import * as api from './socket.api' export default { socket, @@ -13,6 +14,7 @@ export default { system, live, task, + api, } socket.on('status', (data) => { diff --git a/app/client/socket/socket.api.js b/app/client/socket/socket.api.js new file mode 100644 index 0000000..99c9248 --- /dev/null +++ b/app/client/socket/socket.api.js @@ -0,0 +1,32 @@ +import { dispatch } from '../store' +import types from '../types' +import { socket } from './socket.connection' + +socket.on('api_res', (data) => { + // console.log('system response', data) + const type = types[data.datatype] + if (! type) return console.error('socket:api_res bad datatype', data.datatype) + switch (data.type) { + case 'create': + return dispatch({ + type: type.create, + source: 'socket', + data: data.data, + }) + case 'update': + return dispatch({ + type: type.update, + source: 'socket', + data: data.data, + }) + case 'destroy': + return dispatch({ + type: type.destroy, + source: 'socket', + data: data.data, + }) + default: + break + } +}) + |
