2021-03-26 13:38:49 +08:00
|
|
|
|
2021-03-27 04:40:40 +08:00
|
|
|
import ReactDOM from 'react-dom'
|
|
|
|
import React from 'react'
|
2021-03-27 03:18:11 +08:00
|
|
|
import { Root } from './app.jsx'
|
2021-03-26 17:25:28 +08:00
|
|
|
|
2021-03-29 10:23:24 +08:00
|
|
|
|
|
|
|
import { createStore, applyMiddleware } from 'redux'
|
|
|
|
import logger from 'redux-logger'
|
|
|
|
|
2021-03-29 18:27:34 +08:00
|
|
|
let _entId = 0
|
2021-03-29 10:23:24 +08:00
|
|
|
|
|
|
|
function reducer(state = {}, action) {
|
|
|
|
switch (action.type) {
|
2021-03-29 18:27:34 +08:00
|
|
|
case 'rx-sketch':
|
|
|
|
return {
|
2021-04-01 08:04:14 +08:00
|
|
|
...state,
|
|
|
|
treeEntries: {
|
2021-04-01 13:35:08 +08:00
|
|
|
byNid: { ...state.treeEntries.byNid, [action.obj.obj3d.name]: action.obj },
|
|
|
|
allNids: [...state.treeEntries.allNids, action.obj.obj3d.name]
|
2021-04-01 08:04:14 +08:00
|
|
|
}
|
2021-03-30 13:13:13 +08:00
|
|
|
}
|
|
|
|
case 'set-active-sketch':
|
2021-04-01 13:35:08 +08:00
|
|
|
console.log('action',action)
|
2021-03-30 13:13:13 +08:00
|
|
|
return {
|
2021-04-01 13:35:08 +08:00
|
|
|
...state, activeSketchNid: action.sketch
|
2021-03-30 13:13:13 +08:00
|
|
|
}
|
|
|
|
case 'exit-sketch':
|
|
|
|
return {
|
2021-04-01 13:35:08 +08:00
|
|
|
...state, activeSketchNid: ''
|
2021-03-29 18:27:34 +08:00
|
|
|
}
|
|
|
|
case 'rx-extrusion':
|
|
|
|
return {
|
|
|
|
...state,
|
2021-04-01 08:04:14 +08:00
|
|
|
treeEntries: {
|
2021-04-01 13:35:08 +08:00
|
|
|
byNid: { ...state.treeEntries.byNid, [action.mesh.name]: action.mesh },
|
|
|
|
allNids: [...state.treeEntries.allNids, action.mesh.name]
|
2021-04-01 08:04:14 +08:00
|
|
|
},
|
2021-03-29 18:27:34 +08:00
|
|
|
mesh2sketch: {
|
|
|
|
...state.mesh2sketch,
|
2021-04-01 13:35:08 +08:00
|
|
|
[action.sketch.obj3d.name]: action.mesh.name
|
2021-03-29 18:27:34 +08:00
|
|
|
}
|
|
|
|
}
|
2021-04-01 06:03:35 +08:00
|
|
|
case 'restore-state':
|
|
|
|
return action.state
|
2021-03-29 10:23:24 +08:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 18:27:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const preloadedState = {
|
2021-04-01 08:04:14 +08:00
|
|
|
treeEntries: {
|
2021-04-01 13:35:08 +08:00
|
|
|
byNid: {},
|
|
|
|
allNids: []
|
2021-04-01 08:04:14 +08:00
|
|
|
}
|
2021-03-29 18:27:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
window.store = createStore(reducer, preloadedState, applyMiddleware(logger))
|
2021-03-29 10:23:24 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-27 03:18:11 +08:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
ReactDOM.render(
|
|
|
|
React.createElement(Root, { store: store }, null)
|
2021-03-27 04:40:40 +08:00
|
|
|
, document.getElementById('react')
|
2021-03-27 03:18:11 +08:00
|
|
|
);
|
2021-03-27 04:40:40 +08:00
|
|
|
});
|