Skip to content

Commit

Permalink
perf(platform): element assemble: code edit: optimize "change code ve…
Browse files Browse the repository at this point in the history
…ry slow"

reason
when change code, should not create monaco

solution
only when select input/action or code edit unmount or run, update code
  • Loading branch information
yyc-git committed Feb 19, 2024
1 parent 3440cf4 commit ad6e643
Show file tree
Hide file tree
Showing 19 changed files with 522 additions and 289 deletions.
31 changes: 21 additions & 10 deletions doc/1.3.0.org
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,12 @@ TODO update:

* DONE fix(platform): create input->set name to exist name->change name to other name: will create dupliate one

* TODO perf(platform): code edit: if change code, not create monaco
* DONE perf(platform): code edit: if change code, not create monaco

# onChange too slow?

if not select action/input, not create react.monaco!
if select action/input or didMount, dispatch


* TODO fix: editor: run-stop: should reset arcball in gameview when stop
Expand All @@ -764,26 +769,32 @@ TODO update:



# * TODO 3D贪吃蛇

# Snake, Scene use gltf model!
* TODO publish v1.3.0




* TODO 3D贪吃蛇

Snake, Scene use gltf model!


# script:
# control visiable
# bind keyboard event to switch scene
script:
control visiable
bind keyboard event to switch scene



# TODO unbind event when stop
TODO unbind event when stop


# ** TODO add 2d ui
** TODO add 2d ui

# ** TODO ...
** TODO ...


* TODO publish
* TODO publish v1.3.1


# TODO update pro
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,20 @@ module Method = {
}, _)
}

let editorWillUnmount = (editor, monaco) => {
// Js.log("unmound")

let editorWillUnmount = (eventEmitter: Event.eventEmitter, editor, monaco) => {
eventEmitter.emit(. EventUtils.getCodeEditUnmountEventName(), Obj.magic(1))
Js.Promise.resolve()
}

let useSelector = ({assembleSpaceState, eventEmitter}: AppStoreType.state) => {
eventEmitter
}
}

@react.component
let make = (~service: service, ~code, ~getNewCodeFunc) => {
let eventEmitter = service.react.useAllSelector(. Method.useSelector)

let tsProxy = service.react.useRef(None)
let editor = service.react.useRef(None)

Expand Down Expand Up @@ -157,7 +162,7 @@ let make = (~service: service, ~code, ~getNewCodeFunc) => {
value={code}
onChange={Method.onChange(getNewCodeFunc, (tsProxy, editor))}
editorDidMount={Method.editorDidMount((tsProxy, editor))}
editorWillUnmount={Method.editorWillUnmount}
editorWillUnmount={Method.editorWillUnmount(eventEmitter)}
/>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ let make = (~service: service, ~currentCustomActionName) => {
getCurrentCustomNameFromGlobalFunc=CodeEditUtils.getCurrentCustomActionNameFromGlobal
getNameFunc=CustomUtils.getActionName
setCurrentCustomNameToGlobalFunc=CodeEditUtils.setCurrentCustomActionNameToGlobal
buildUpdateActionFunc={(
name,
newName,
newOriginCode,
newTranspiledCode,
) => ElementAssembleStoreType.UpdateCustomActionFileStr(
name,
newName,
newOriginCode,
newTranspiledCode,
)}
// buildUpdateActionFunc={(
// name,
// newName,
// newOriginCode,
// newTranspiledCode,
// ) => ElementAssembleStoreType.UpdateCustomActionFileStr(
// name,
// newName,
// newOriginCode,
// newTranspiledCode,
// )}
currentCustomName=currentCustomActionName
customs=customActions
// customs=customActions
type_=CommonType.Action
/>
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,6 @@ let make = (~service: service, ~addActionButtonTarget: React.ref<Js.Nullable.t<'
currentCustomName=currentCustomActionName
customs=customActions
prefix="Action"
type_=CommonType.Action
/>
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,27 @@ module Method = {
}

@react.component
let make = (
~service: service,
~currentCustomInputName,
) => {
let make = (~service: service, ~currentCustomInputName) => {
let customInputs = service.react.useSelector(. Method.useSelector)

<CustomCodeEditUtils
service
getCurrentCustomNameFromGlobalFunc=CodeEditUtils.getCurrentCustomInputNameFromGlobal
getNameFunc=CustomUtils.getInputName
setCurrentCustomNameToGlobalFunc=CodeEditUtils.setCurrentCustomInputNameToGlobal
buildUpdateActionFunc={(
name,
newName,
newOriginCode,
newTranspiledCode,
) => ElementAssembleStoreType.UpdateCustomInputFileStr(
name,
newName,
newOriginCode,
newTranspiledCode,
)}
// buildUpdateActionFunc={(
// name,
// newName,
// newOriginCode,
// newTranspiledCode,
// ) => ElementAssembleStoreType.UpdateCustomInputFileStr(
// name,
// newName,
// newOriginCode,
// newTranspiledCode,
// )}
currentCustomName=currentCustomInputName
customs=customInputs
// customs=customInputs
type_=CommonType.Input
/>
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ let make = (~service: service, ~addInputButtonTarget: React.ref<Js.Nullable.t<'a
currentCustomName=currentCustomInputName
customs=customInputs
prefix="Input"
type_=CommonType.Input
/>
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ let _createState = () => {
customActions: list{},
currentCustomInputName: None,
currentCustomActionName: None,
currentCode: EmptyCode,
// currentChangeCode: EmptyChangeCode,
isInCreateFromScratchTourPhase2: false,
// isJumpToCreateFromScratchTourPhase2Guide: false,
}
Expand Down Expand Up @@ -191,6 +193,16 @@ let _reset = state => {
}
}

let _isNameExist = (newName, oldName, customs) => {
newName == oldName
? false
: customs
->Meta3dCommonlib.ListSt.find((custom: CommonType.custom) => {
custom.name == newName
})
->Meta3dCommonlib.OptionSt.isSome
}

let reducer = (state, action) => {
switch action {
| ResetWhenEnter => state->_reset
Expand Down Expand Up @@ -436,54 +448,93 @@ let reducer = (state, action) => {
}),
})
}
| UpdateCustomInputFileStr(oldInputName, newInputName, newOriginCode, newTranspiledCode) => {
let state = {
...state,
customInputs: state.customInputs->Meta3dCommonlib.ListSt.map(customInput => {
customInput.name == oldInputName
? (
{
...customInput,
name: newInputName,
originFileStr: newOriginCode->Some,
transpiledFileStr: newTranspiledCode,
}: customInput
)
: customInput
}),
}
| UpdateCustomFileStr(handleNameExistFunc) =>
// let state = switch state.currentChangeCode {
// | Change(customType, oldName, newName, newOriginCode, newTranspiledCode) =>
let state = switch CodeEditUtils.getChangeCodeDataToGlobal()->Meta3dCommonlib.OptionSt.fromNullable {
| Some((customType, oldName, newName, newOriginCode, newTranspiledCode)) =>
switch customType {
| CommonType.Action =>
_isNameExist(newName, oldName, state.customActions)
? {
handleNameExistFunc()
state
}
: {
let state = {
...state,
customActions: state.customActions->Meta3dCommonlib.ListSt.map(custom => {
custom.name == oldName
? (
{
name: newName,
originFileStr: newOriginCode->Some,
transpiledFileStr: newTranspiledCode,
}: customAction
)
: custom
}),
}

state->_updateAllUIControlInspectorData(data => {
...data,
input: data.input->Meta3dCommonlib.OptionSt.map(({inputName}): input => {
inputName: inputName == oldInputName ? newInputName : inputName,
}),
})
}
| UpdateCustomActionFileStr(oldActionName, newActionName, newOriginCode, newTranspiledCode) => {
let state = {
...state,
customActions: state.customActions->Meta3dCommonlib.ListSt.map(customAction => {
customAction.name == oldActionName
? (
{
name: newActionName,
originFileStr: newOriginCode->Some,
transpiledFileStr: newTranspiledCode,
}: customAction
)
: customAction
}),
state->_updateAllUIControlInspectorData(data => {
...data,
event: data.event->Meta3dCommonlib.ArraySt.map(action => {
...action,
actionName: action.actionName == oldName ? newName : action.actionName,
}),
})
}

| CommonType.Input =>
_isNameExist(newName, oldName, state.customActions)
? {
handleNameExistFunc()
state
}
: {
let state = {
...state,
customInputs: state.customInputs->Meta3dCommonlib.ListSt.map(custom => {
custom.name == oldName
? (
{
...custom,
name: newName,
originFileStr: newOriginCode->Some,
transpiledFileStr: newTranspiledCode,
}: customInput
)
: custom
}),
}

state->_updateAllUIControlInspectorData(data => {
...data,
input: data.input->Meta3dCommonlib.OptionSt.map(({inputName}): input => {
inputName: inputName == oldName ? newName : inputName,
}),
})
}
}
| None => state
}

state->_updateAllUIControlInspectorData(data => {
...data,
event: data.event->Meta3dCommonlib.ArraySt.map(action => {
...action,
actionName: action.actionName == oldActionName ? newActionName : action.actionName,
}),
})
// CodeEditUtils.setChangeCodeDataToGlobal(Meta3dCommonlib.NullableSt.getEmpty())

// {
// ...state,
// currentCode: EmptyCode,
// // currentChangeCode: EmptyChangeCode,
// }
state
| SetCode(code) => {
...state,
currentCode: code,
}
// | SetChangeCode(code) => {
// ...state,
// currentChangeCode: code,
// }
| SelectCustomInput(inputName) => {
...state->_resetCurrent,
currentCustomInputName: inputName->Some,
Expand Down
Loading

0 comments on commit ad6e643

Please sign in to comment.