Skip to content

Commit ad6e643

Browse files
committed
perf(platform): element assemble: code edit: optimize "change code very slow"
reason when change code, should not create monaco solution only when select input/action or code edit unmount or run, update code
1 parent 3440cf4 commit ad6e643

File tree

19 files changed

+522
-289
lines changed

19 files changed

+522
-289
lines changed

doc/1.3.0.org

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,12 @@ TODO update:
755755

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

758-
* TODO perf(platform): code edit: if change code, not create monaco
758+
* DONE perf(platform): code edit: if change code, not create monaco
759+
760+
# onChange too slow?
761+
762+
if not select action/input, not create react.monaco!
763+
if select action/input or didMount, dispatch
759764

760765

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

765770

766771

767-
# * TODO 3D贪吃蛇
768772

769-
# Snake, Scene use gltf model!
773+
* TODO publish v1.3.0
774+
775+
776+
777+
778+
* TODO 3D贪吃蛇
779+
780+
Snake, Scene use gltf model!
770781

771782

772-
# script:
773-
# control visiable
774-
# bind keyboard event to switch scene
783+
script:
784+
control visiable
785+
bind keyboard event to switch scene
775786

776787

777788

778-
# TODO unbind event when stop
789+
TODO unbind event when stop
779790

780791

781-
# ** TODO add 2d ui
792+
** TODO add 2d ui
782793

783-
# ** TODO ...
794+
** TODO ...
784795

785796

786-
* TODO publish
797+
* TODO publish v1.3.1
787798

788799

789800
# TODO update pro

platform/frontend/src/external_layer/ui/app/assemble_space/components/element_assemble/code_edit/CodeEdit.res

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,20 @@ module Method = {
9797
}, _)
9898
}
9999

100-
let editorWillUnmount = (editor, monaco) => {
101-
// Js.log("unmound")
102-
100+
let editorWillUnmount = (eventEmitter: Event.eventEmitter, editor, monaco) => {
101+
eventEmitter.emit(. EventUtils.getCodeEditUnmountEventName(), Obj.magic(1))
103102
Js.Promise.resolve()
104103
}
104+
105+
let useSelector = ({assembleSpaceState, eventEmitter}: AppStoreType.state) => {
106+
eventEmitter
107+
}
105108
}
106109

107110
@react.component
108111
let make = (~service: service, ~code, ~getNewCodeFunc) => {
112+
let eventEmitter = service.react.useAllSelector(. Method.useSelector)
113+
109114
let tsProxy = service.react.useRef(None)
110115
let editor = service.react.useRef(None)
111116

@@ -157,7 +162,7 @@ let make = (~service: service, ~code, ~getNewCodeFunc) => {
157162
value={code}
158163
onChange={Method.onChange(getNewCodeFunc, (tsProxy, editor))}
159164
editorDidMount={Method.editorDidMount((tsProxy, editor))}
160-
editorWillUnmount={Method.editorWillUnmount}
165+
editorWillUnmount={Method.editorWillUnmount(eventEmitter)}
161166
/>
162167
}
163168
}

platform/frontend/src/external_layer/ui/app/assemble_space/components/element_assemble/custom_action_code_edit/CustomActionCodeEdit.res

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ let make = (~service: service, ~currentCustomActionName) => {
1919
getCurrentCustomNameFromGlobalFunc=CodeEditUtils.getCurrentCustomActionNameFromGlobal
2020
getNameFunc=CustomUtils.getActionName
2121
setCurrentCustomNameToGlobalFunc=CodeEditUtils.setCurrentCustomActionNameToGlobal
22-
buildUpdateActionFunc={(
23-
name,
24-
newName,
25-
newOriginCode,
26-
newTranspiledCode,
27-
) => ElementAssembleStoreType.UpdateCustomActionFileStr(
28-
name,
29-
newName,
30-
newOriginCode,
31-
newTranspiledCode,
32-
)}
22+
// buildUpdateActionFunc={(
23+
// name,
24+
// newName,
25+
// newOriginCode,
26+
// newTranspiledCode,
27+
// ) => ElementAssembleStoreType.UpdateCustomActionFileStr(
28+
// name,
29+
// newName,
30+
// newOriginCode,
31+
// newTranspiledCode,
32+
// )}
3333
currentCustomName=currentCustomActionName
34-
customs=customActions
34+
// customs=customActions
35+
type_=CommonType.Action
3536
/>
3637
}

platform/frontend/src/external_layer/ui/app/assemble_space/components/element_assemble/custom_actions/components/CustomActions.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,6 @@ let make = (~service: service, ~addActionButtonTarget: React.ref<Js.Nullable.t<'
6868
currentCustomName=currentCustomActionName
6969
customs=customActions
7070
prefix="Action"
71+
type_=CommonType.Action
7172
/>
7273
}

platform/frontend/src/external_layer/ui/app/assemble_space/components/element_assemble/custom_input_code_edit/CustomInputCodeEdit.res

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,27 @@ module Method = {
1111
}
1212

1313
@react.component
14-
let make = (
15-
~service: service,
16-
~currentCustomInputName,
17-
) => {
14+
let make = (~service: service, ~currentCustomInputName) => {
1815
let customInputs = service.react.useSelector(. Method.useSelector)
1916

2017
<CustomCodeEditUtils
2118
service
2219
getCurrentCustomNameFromGlobalFunc=CodeEditUtils.getCurrentCustomInputNameFromGlobal
2320
getNameFunc=CustomUtils.getInputName
2421
setCurrentCustomNameToGlobalFunc=CodeEditUtils.setCurrentCustomInputNameToGlobal
25-
buildUpdateActionFunc={(
26-
name,
27-
newName,
28-
newOriginCode,
29-
newTranspiledCode,
30-
) => ElementAssembleStoreType.UpdateCustomInputFileStr(
31-
name,
32-
newName,
33-
newOriginCode,
34-
newTranspiledCode,
35-
)}
22+
// buildUpdateActionFunc={(
23+
// name,
24+
// newName,
25+
// newOriginCode,
26+
// newTranspiledCode,
27+
// ) => ElementAssembleStoreType.UpdateCustomInputFileStr(
28+
// name,
29+
// newName,
30+
// newOriginCode,
31+
// newTranspiledCode,
32+
// )}
3633
currentCustomName=currentCustomInputName
37-
customs=customInputs
34+
// customs=customInputs
35+
type_=CommonType.Input
3836
/>
3937
}

platform/frontend/src/external_layer/ui/app/assemble_space/components/element_assemble/custom_inputs/components/CustomInputs.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,6 @@ let make = (~service: service, ~addInputButtonTarget: React.ref<Js.Nullable.t<'a
4747
currentCustomName=currentCustomInputName
4848
customs=customInputs
4949
prefix="Input"
50+
type_=CommonType.Input
5051
/>
5152
}

platform/frontend/src/external_layer/ui/app/assemble_space/components/element_assemble/store/ElementAssembleStore.res

Lines changed: 95 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ let _createState = () => {
4343
customActions: list{},
4444
currentCustomInputName: None,
4545
currentCustomActionName: None,
46+
currentCode: EmptyCode,
47+
// currentChangeCode: EmptyChangeCode,
4648
isInCreateFromScratchTourPhase2: false,
4749
// isJumpToCreateFromScratchTourPhase2Guide: false,
4850
}
@@ -191,6 +193,16 @@ let _reset = state => {
191193
}
192194
}
193195

196+
let _isNameExist = (newName, oldName, customs) => {
197+
newName == oldName
198+
? false
199+
: customs
200+
->Meta3dCommonlib.ListSt.find((custom: CommonType.custom) => {
201+
custom.name == newName
202+
})
203+
->Meta3dCommonlib.OptionSt.isSome
204+
}
205+
194206
let reducer = (state, action) => {
195207
switch action {
196208
| ResetWhenEnter => state->_reset
@@ -436,54 +448,93 @@ let reducer = (state, action) => {
436448
}),
437449
})
438450
}
439-
| UpdateCustomInputFileStr(oldInputName, newInputName, newOriginCode, newTranspiledCode) => {
440-
let state = {
441-
...state,
442-
customInputs: state.customInputs->Meta3dCommonlib.ListSt.map(customInput => {
443-
customInput.name == oldInputName
444-
? (
445-
{
446-
...customInput,
447-
name: newInputName,
448-
originFileStr: newOriginCode->Some,
449-
transpiledFileStr: newTranspiledCode,
450-
}: customInput
451-
)
452-
: customInput
453-
}),
454-
}
451+
| UpdateCustomFileStr(handleNameExistFunc) =>
452+
// let state = switch state.currentChangeCode {
453+
// | Change(customType, oldName, newName, newOriginCode, newTranspiledCode) =>
454+
let state = switch CodeEditUtils.getChangeCodeDataToGlobal()->Meta3dCommonlib.OptionSt.fromNullable {
455+
| Some((customType, oldName, newName, newOriginCode, newTranspiledCode)) =>
456+
switch customType {
457+
| CommonType.Action =>
458+
_isNameExist(newName, oldName, state.customActions)
459+
? {
460+
handleNameExistFunc()
461+
state
462+
}
463+
: {
464+
let state = {
465+
...state,
466+
customActions: state.customActions->Meta3dCommonlib.ListSt.map(custom => {
467+
custom.name == oldName
468+
? (
469+
{
470+
name: newName,
471+
originFileStr: newOriginCode->Some,
472+
transpiledFileStr: newTranspiledCode,
473+
}: customAction
474+
)
475+
: custom
476+
}),
477+
}
455478

456-
state->_updateAllUIControlInspectorData(data => {
457-
...data,
458-
input: data.input->Meta3dCommonlib.OptionSt.map(({inputName}): input => {
459-
inputName: inputName == oldInputName ? newInputName : inputName,
460-
}),
461-
})
462-
}
463-
| UpdateCustomActionFileStr(oldActionName, newActionName, newOriginCode, newTranspiledCode) => {
464-
let state = {
465-
...state,
466-
customActions: state.customActions->Meta3dCommonlib.ListSt.map(customAction => {
467-
customAction.name == oldActionName
468-
? (
469-
{
470-
name: newActionName,
471-
originFileStr: newOriginCode->Some,
472-
transpiledFileStr: newTranspiledCode,
473-
}: customAction
474-
)
475-
: customAction
476-
}),
479+
state->_updateAllUIControlInspectorData(data => {
480+
...data,
481+
event: data.event->Meta3dCommonlib.ArraySt.map(action => {
482+
...action,
483+
actionName: action.actionName == oldName ? newName : action.actionName,
484+
}),
485+
})
486+
}
487+
488+
| CommonType.Input =>
489+
_isNameExist(newName, oldName, state.customActions)
490+
? {
491+
handleNameExistFunc()
492+
state
493+
}
494+
: {
495+
let state = {
496+
...state,
497+
customInputs: state.customInputs->Meta3dCommonlib.ListSt.map(custom => {
498+
custom.name == oldName
499+
? (
500+
{
501+
...custom,
502+
name: newName,
503+
originFileStr: newOriginCode->Some,
504+
transpiledFileStr: newTranspiledCode,
505+
}: customInput
506+
)
507+
: custom
508+
}),
509+
}
510+
511+
state->_updateAllUIControlInspectorData(data => {
512+
...data,
513+
input: data.input->Meta3dCommonlib.OptionSt.map(({inputName}): input => {
514+
inputName: inputName == oldName ? newName : inputName,
515+
}),
516+
})
517+
}
477518
}
519+
| None => state
520+
}
478521

479-
state->_updateAllUIControlInspectorData(data => {
480-
...data,
481-
event: data.event->Meta3dCommonlib.ArraySt.map(action => {
482-
...action,
483-
actionName: action.actionName == oldActionName ? newActionName : action.actionName,
484-
}),
485-
})
522+
// CodeEditUtils.setChangeCodeDataToGlobal(Meta3dCommonlib.NullableSt.getEmpty())
523+
524+
// {
525+
// ...state,
526+
// currentCode: EmptyCode,
527+
// // currentChangeCode: EmptyChangeCode,
528+
// }
529+
state
530+
| SetCode(code) => {
531+
...state,
532+
currentCode: code,
486533
}
534+
// | SetChangeCode(code) => {
535+
// ...state,
536+
// currentChangeCode: code,
537+
// }
487538
| SelectCustomInput(inputName) => {
488539
...state->_resetCurrent,
489540
currentCustomInputName: inputName->Some,

0 commit comments

Comments
 (0)