-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Vue generator and support for reactive variables
- Loading branch information
Showing
3 changed files
with
65 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {javascriptGenerator, JavascriptGenerator} from "blockly/javascript"; | ||
import {Names, Variables, Workspace} from "blockly"; | ||
import NameType = Names.NameType; | ||
|
||
class VueGenerator extends JavascriptGenerator { | ||
init(workspace: Workspace) { | ||
super.init(workspace); | ||
|
||
if (!this.nameDB_) { | ||
this.nameDB_ = new Names(this.RESERVED_WORDS_); | ||
} else { | ||
this.nameDB_.reset(); | ||
} | ||
|
||
this.nameDB_.setVariableMap(workspace.getVariableMap()); | ||
this.nameDB_.populateVariables(workspace); | ||
this.nameDB_.populateProcedures(workspace); | ||
|
||
const defvars = []; | ||
// Add developer variables (not created or named by the user). | ||
const devVarList = Variables.allDeveloperVariables(workspace); | ||
for (let i = 0; i < devVarList.length; i++) { | ||
defvars.push( | ||
this.nameDB_.getName(devVarList[i], NameType.DEVELOPER_VARIABLE), | ||
); | ||
} | ||
|
||
// Add user variables, but only ones that are being used. | ||
const variables = Variables.allUsedVarModels(workspace); | ||
for (let i = 0; i < variables.length; i++) { | ||
defvars.push( | ||
this.nameDB_.getName(variables[i].getId(), NameType.VARIABLE), | ||
); | ||
} | ||
|
||
// Declare all of the variables. | ||
if (defvars.length) { | ||
this.definitions_['variables'] = `let state = reactive({${defvars.map(v => `${v}: null`).join(',')}})`; | ||
} | ||
this.isInitialized = true; | ||
} | ||
} | ||
|
||
export const vueGenerator = new VueGenerator('vue'); | ||
|
||
|
||
for (const name in javascriptGenerator.forBlock) { | ||
vueGenerator.forBlock[name] = javascriptGenerator.forBlock[name]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters