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 = () => {
253253 const [ deleteTooltip , setDeleteTooltip ] = useState ( 'Delete' ) ;
254254 const blocklyComponent = useRef < BlocklyComponentType | null > ( null ) ;
255255 const [ triggerPythonRegeneration , setTriggerPythonRegeneration ] = useState ( 0 ) ;
256- const generatorContext = useRef ( createGeneratorContext ( ) ) ;
256+ const generatorContext = useRef < GeneratorContext | null > ( null ) ;
257257 const blocksEditor = useRef < editor . Editor | null > ( null ) ;
258258 const [ generatedCode , setGeneratedCode ] = useState ( '' ) ;
259259 const [ newProjectNameModalPurpose , setNewProjectNameModalPurpose ] = useState ( '' ) ;
@@ -534,7 +534,8 @@ const App: React.FC = () => {
534534 blocklyWorkspace . addChangeListener ( mutatorOpenListener ) ;
535535 blocklyWorkspace . addChangeListener ( handleBlocksChanged ) ;
536536 }
537- blocksEditor . current = new editor . Editor ( blocklyWorkspace , storage ) ;
537+ generatorContext . current = createGeneratorContext ( ) ;
538+ blocksEditor . current = new editor . Editor ( blocklyWorkspace , generatorContext . current , storage ) ;
538539 } , [ blocklyComponent , storage ] ) ;
539540
540541 const handleBlocksChanged = ( event : Blockly . Events . Abstract ) => {
Original file line number Diff line number Diff line change 2222import * as Blockly from 'blockly/core' ;
2323
2424import { extendedPythonGenerator } from './extended_python_generator' ;
25- import { createGeneratorContext , GeneratorContext } from './generator_context' ;
25+ import { GeneratorContext } from './generator_context' ;
2626import * as commonStorage from '../storage/common_storage' ;
2727import { getToolboxJSON } from '../toolbox/toolbox' ;
2828
@@ -33,8 +33,8 @@ const EMPTY_TOOLBOX: Blockly.utils.toolbox.ToolboxDefinition = {
3333} ;
3434
3535export class Editor {
36- private generatorContext = createGeneratorContext ( ) ;
3736 private blocklyWorkspace : Blockly . WorkspaceSvg ;
37+ private generatorContext : GeneratorContext ;
3838 private storage : commonStorage . Storage ;
3939 private currentModule : commonStorage . Module | null = null ;
4040 private modulePath : string = '' ;
@@ -44,8 +44,9 @@ export class Editor {
4444 private bindedOnChange : any = null ;
4545 private toolbox : Blockly . utils . toolbox . ToolboxDefinition = EMPTY_TOOLBOX ;
4646
47- constructor ( blocklyWorkspace : Blockly . WorkspaceSvg , storage : commonStorage . Storage ) {
47+ constructor ( blocklyWorkspace : Blockly . WorkspaceSvg , generatorContext : GeneratorContext , storage : commonStorage . Storage ) {
4848 this . blocklyWorkspace = blocklyWorkspace ;
49+ this . generatorContext = generatorContext ;
4950 this . storage = storage ;
5051 }
5152
Original file line number Diff line number Diff line change @@ -97,13 +97,15 @@ export class GeneratorContext {
9797 }
9898
9999 addClassMethodName ( nameFieldValue : string , methodName : string ) {
100- this . classMethodNames [ nameFieldValue ] = methodName ;
100+ if ( nameFieldValue !== methodName ) {
101+ this . classMethodNames [ nameFieldValue ] = methodName ;
102+ }
101103 }
102104
103105 getClassMethodName ( nameFieldValue : string ) : string | null {
104- if ( nameFieldValue in this . classMethodNames ) {
106+ if ( this . classMethodNames [ nameFieldValue ] ) {
105107 return this . classMethodNames [ nameFieldValue ] ;
106108 }
107- return null ;
109+ return nameFieldValue ;
108110 }
109111}
You can’t perform that action at this time.
0 commit comments