Skip to content

Commit

Permalink
feat: make procedure def blocks respond to model updates
Browse files Browse the repository at this point in the history
  • Loading branch information
BeksOmega committed Dec 5, 2022
1 parent d1653fe commit 007dffb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
29 changes: 23 additions & 6 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ const procedureDefGetDefMixin = function() {
},
};

mixin.model = new ObservableProcedureModel(
this.workspace, this.getFieldValue('NAME'));
mixin.model =
new ObservableProcedureModel(this.workspace, this.getFieldValue('NAME'));
this.workspace.getProcedureMap().add(mixin.model);

this.mixin(mixin, true);
Expand Down Expand Up @@ -382,6 +382,27 @@ const procedureDefVarMixin = function() {
Extensions.register('procedure_def_var_mixin', procedureDefVarMixin);

const procedureDefUpdateShapeMixin = {
doProcedureUpdate: function() {
this.setFieldValue(this.model.getName(), 'NAME');
this.setEnabled(this.model.getEnabled());
this.updateParameters_();
},

updateParameters_: function() {
const params = this.model.getParameters().map((p) => p.getName());
const paramString = params.length ?
`${Msg['PROCEDURES_BEFORE_PARAMS']} ${params.join(', ')}` :
'';

// The field is deterministic based on other events, no need to fire.
Events.disable();
try {
this.setFieldValue(paramString, 'PARAMS');
} finally {
Events.enable();
}
},

/**
* Add or remove the statement block from this function definition.
* @param {boolean} hasStatements True if a statement block is needed.
Expand Down Expand Up @@ -660,16 +681,12 @@ const procedureDefMutator = {
this.paramIds_ = [];
this.argumentVarModels_ = [];

console.log('called');

// TODO: Remove old data handling logic?
let paramBlock = containerBlock.getInputTargetBlock('STACK');
console.log(containerBlock, paramBlock);
while (paramBlock && !paramBlock.isInsertionMarker()) {
console.log('looping!');
const varName = paramBlock.getFieldValue('NAME');
this.arguments_.push(varName);
console.log(this.workspace.getVariableMap().getVariablesOfType(''));
const variable = this.workspace.getVariable(varName, '');
this.argumentVarModels_.push(variable);

Expand Down
8 changes: 4 additions & 4 deletions tests/mocha/blocks/procedures_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ suite('Procedures', function() {
sharedTestTeardown.call(this);
});

suite.only('updating data models', function() {
suite('updating data models', function() {
test(
'renaming a procedure def block updates the procedure model',
function() {
Expand Down Expand Up @@ -187,8 +187,8 @@ suite('Procedures', function() {
});
});

suite.skip('responding to data model updates', function() {
suite('def blocks', function() {
suite.only('responding to data model updates', function() {
suite.only('def blocks', function() {
test('renaming the procedure data model updates blocks', function() {
const defBlock = createProcDefBlock(this.workspace);
const procModel = defBlock.getProcedureModel();
Expand All @@ -208,7 +208,7 @@ suite('Procedures', function() {
procModel.setEnabled(false);

chai.assert.isFalse(
defBlock.getEnabled(),
defBlock.isEnabled(),
'Expected the procedure block to be disabled');
});

Expand Down

0 comments on commit 007dffb

Please sign in to comment.