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 9, 2022
1 parent dec458a commit fa7c1c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
25 changes: 23 additions & 2 deletions blocks/procedures.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,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 @@ -391,6 +391,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
6 changes: 3 additions & 3 deletions tests/mocha/blocks/procedures_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,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 @@ -244,7 +244,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 fa7c1c0

Please sign in to comment.