Front end changes for cadquery
Basic changes to get the proof of concept working. Lots of attention was given to the store/reducer to solve existing problems with async code and stale closures, it seems even today how to handle this with use reducer is not quiet settle, I guess because once an app reaches a certain level of maturity everyone grabs an off the shelf solution to state management. I ended up implementing thunks because they are really rather simple. Interesting thread about it all here: https://gist.github.com/astoilkov/013c513e33fe95fa8846348038d8fe42#gistcomment-3377800 I also move some of settings that were persisted in the openScad controller into the data store as I ulimately thing what I was doing in that file was very confusing, with the fact that it had to be called multiple times with different information before it would be able to render something properly.
This commit is contained in:
@@ -2,33 +2,16 @@ let openScadBaseURL =
|
||||
process.env.OPENSCAD_BASE_URL ||
|
||||
'https://x2wvhihk56.execute-api.us-east-1.amazonaws.com/dev'
|
||||
|
||||
let lastViewPortSize = 'INIT'
|
||||
let lastCameraSettings = 'INIT'
|
||||
|
||||
export const render = async ({ code, settings }) => {
|
||||
const pixelRatio = window.devicePixelRatio || 1
|
||||
const size = settings.viewerSize
|
||||
? {
|
||||
x: Math.round(settings.viewerSize?.width * pixelRatio),
|
||||
y: Math.round(settings.viewerSize?.height * pixelRatio),
|
||||
}
|
||||
: lastViewPortSize
|
||||
const camera = settings.camera || lastCameraSettings
|
||||
if (settings.camera) {
|
||||
lastCameraSettings = settings.camera
|
||||
}
|
||||
if (settings.viewerSize) {
|
||||
lastViewPortSize = size
|
||||
}
|
||||
if ([camera, size].includes('INIT')) {
|
||||
return {
|
||||
status: 'insufficient-preview-info',
|
||||
}
|
||||
const size = {
|
||||
x: Math.round(settings.viewerSize?.width * pixelRatio),
|
||||
y: Math.round(settings.viewerSize?.height * pixelRatio),
|
||||
}
|
||||
const body = JSON.stringify({
|
||||
settings: {
|
||||
size,
|
||||
camera,
|
||||
camera: settings.camera,
|
||||
},
|
||||
file: code,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user