File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -253,7 +253,7 @@ const App: React.FC = () => {
253
253
const [ deleteTooltip , setDeleteTooltip ] = useState ( 'Delete' ) ;
254
254
const blocklyComponent = useRef < BlocklyComponentType | null > ( null ) ;
255
255
const [ triggerPythonRegeneration , setTriggerPythonRegeneration ] = useState ( 0 ) ;
256
- const generatorContext = useRef ( createGeneratorContext ( ) ) ;
256
+ const generatorContext = useRef < GeneratorContext | null > ( null ) ;
257
257
const blocksEditor = useRef < editor . Editor | null > ( null ) ;
258
258
const [ generatedCode , setGeneratedCode ] = useState ( '' ) ;
259
259
const [ newProjectNameModalPurpose , setNewProjectNameModalPurpose ] = useState ( '' ) ;
@@ -534,7 +534,8 @@ const App: React.FC = () => {
534
534
blocklyWorkspace . addChangeListener ( mutatorOpenListener ) ;
535
535
blocklyWorkspace . addChangeListener ( handleBlocksChanged ) ;
536
536
}
537
- blocksEditor . current = new editor . Editor ( blocklyWorkspace , storage ) ;
537
+ generatorContext . current = createGeneratorContext ( ) ;
538
+ blocksEditor . current = new editor . Editor ( blocklyWorkspace , generatorContext . current , storage ) ;
538
539
} , [ blocklyComponent , storage ] ) ;
539
540
540
541
const handleBlocksChanged = ( event : Blockly . Events . Abstract ) => {
Original file line number Diff line number Diff line change 22
22
import * as Blockly from 'blockly/core' ;
23
23
24
24
import { extendedPythonGenerator } from './extended_python_generator' ;
25
- import { createGeneratorContext , GeneratorContext } from './generator_context' ;
25
+ import { GeneratorContext } from './generator_context' ;
26
26
import * as commonStorage from '../storage/common_storage' ;
27
27
import { getToolboxJSON } from '../toolbox/toolbox' ;
28
28
@@ -33,8 +33,8 @@ const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
33
33
} ;
34
34
35
35
export class Editor {
36
- private generatorContext = createGeneratorContext ( ) ;
37
36
private blocklyWorkspace : Blockly . WorkspaceSvg ;
37
+ private generatorContext : GeneratorContext ;
38
38
private storage : commonStorage . Storage ;
39
39
private currentModule : commonStorage . Module | null = null ;
40
40
private modulePath : string = '' ;
@@ -44,8 +44,9 @@ export class Editor {
44
44
private bindedOnChange : any = null ;
45
45
private toolbox : Blockly . utils . toolbox . ToolboxDefinition = EMPTY_TOOLBOX ;
46
46
47
- constructor ( blocklyWorkspace : Blockly . WorkspaceSvg , storage : commonStorage . Storage ) {
47
+ constructor ( blocklyWorkspace : Blockly . WorkspaceSvg , generatorContext : GeneratorContext , storage : commonStorage . Storage ) {
48
48
this . blocklyWorkspace = blocklyWorkspace ;
49
+ this . generatorContext = generatorContext ;
49
50
this . storage = storage ;
50
51
}
51
52
Original file line number Diff line number Diff line change @@ -97,13 +97,15 @@ export class GeneratorContext {
97
97
}
98
98
99
99
addClassMethodName ( nameFieldValue : string , methodName : string ) {
100
- this . classMethodNames [ nameFieldValue ] = methodName ;
100
+ if ( nameFieldValue !== methodName ) {
101
+ this . classMethodNames [ nameFieldValue ] = methodName ;
102
+ }
101
103
}
102
104
103
105
getClassMethodName ( nameFieldValue : string ) : string | null {
104
- if ( nameFieldValue in this . classMethodNames ) {
106
+ if ( this . classMethodNames [ nameFieldValue ] ) {
105
107
return this . classMethodNames [ nameFieldValue ] ;
106
108
}
107
- return null ;
109
+ return nameFieldValue ;
108
110
}
109
111
}
You can’t perform that action at this time.
0 commit comments