Skip to content

refactor: ProgramCall.addParam to accept an object - #139

Merged
kadler merged 11 commits into
IBM:masterfrom
abmusse:refactor-addParam
Mar 25, 2020
Merged

refactor: ProgramCall.addParam to accept an object#139
kadler merged 11 commits into
IBM:masterfrom
abmusse:refactor-addParam

Conversation

@abmusse

@abmusseabmusse commented Mar 11, 2020

Copy link
Copy Markdown
Member

Resolves#107

@abmusseabmusse changed the title refactor: Add functions to handle DS and simple data nodesrefactor: ProgramCall.addParam to accept an objectMar 11, 2020
@abmusse
abmusse requested a review from kadlerMarch 11, 2020 18:05
@abmusse
abmusse marked this pull request as ready for review March 11, 2020 18:05
@abmusse

abmusse commented Mar 12, 2020

Copy link
Copy Markdown
MemberAuthor

There is an open proposal to add private methods to JS.

https://github.com/tc39/proposal-private-methods

It is currently a stage 3 candidate.

In the future we could use this syntax instead of using __mehtod__ naming used here.

class ClassWithPrivateMethod {
#privateMethod() {
return 'hello world'
}
getPrivateMessage() {
return #privateMethod()
}
}

@abmusse

abmusse commented Mar 12, 2020

Copy link
Copy Markdown
MemberAuthor

Need to update unit ProgramCallUnit,js tests with this PR.

@kadlerkadler closed this Mar 12, 2020
@kadlerkadler reopened this Mar 12, 2020
@markirishmarkirish mentioned this pull request Mar 13, 2020
Comment threadlib/Deprecated.js
@abmusse
abmusse requested a review from kadlerMarch 23, 2020 03:15
@abmusse

abmusse commented Mar 23, 2020

Copy link
Copy Markdown
MemberAuthor

Functions who use ProgramCall.addParam will need to be updated to pass an object.

This includes methods in the following classes:

  • iDataQueue
  • iNetwork
  • iObj
  • iProd
  • iUserSpace
  • iWork

@kadlerkadler left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit overly complicated. Basically, addData should do something like this:

if type is ds:
create "<ds>" node and set options accordingly
foreach field in ds fields:
xml += addData(field)
append "</ds>"
else:
create "<data>" node and set options accordingly

Comment threadtest/unit/ProgamCallUnit.js Outdated
Comment on lines +28 to +35
['', '10i0', 0],
['', '10i0', 0],
['', '36h', ''],
['', '10A', ''],
['', '1A', ''],
['', '1A', ''],
['', '10i0', 0],
['', '10i0', 0],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't these all need to be objects now?

@abmusseabmusseMar 24, 2020

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm we are on the same page.

How do we want DS to be defined?

Do we want DS to be an array of objects like shown here?
#107 (comment)

consterrno=[// fields can be defined using objects as well// attributes are set on the object itself, not in a separate object{name: 'bytes_provided',type:'10i0',setlen: 'rec2'},{name: 'bytes_available',type: '10i0'},// The value can be set on the object{name: 'msgid',type: '7a',value: 'XXX0000'},// we can also omit names in object format {type: '1h'},// Data structures can also be nested using object format{name: 'message fields',type='ds',fields=[// You can always mix and match object/array fields['field1','10i0'],{name: 'field2',type:'10i0'}]}];

If that is the case then yes we will need to change these to objects.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, all data types should be objects. We can add shortcuts in v1.1 or later.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, that example was before we talked about the problem for ds options. Thus, ds that need options must be objects, but I suggest we just stop supporting arrays for now as I just mentioned.

So something like this, instead:

consterrno={name: "errno",type: "ds",setlen: "whatever",fields: [
# fieldshere]}

@abmusseabmusseMar 24, 2020

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I suggest we just stop supporting arrays for now as I just mentioned.

Thanks! I agree all data types will just be objects for now. We can add shortcuts and options later.

I will also need to update the iPgm wrapper to create ds types as objects.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#157 will be affected as well.

Comment threadlib/ProgramCall.js Outdated
Comment on lines +129 to +130
const nameNode = parameter.name ? ` name='${parameter.name}'` : '';
this.xml += `<parm${nameNode}`;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do this like parameter.io and parameter.by are done below.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks will do

Comment threadlib/ProgramCall.js Outdated
*/
__addData__(parameter = {}) {
// adding a data structure with data nodes
if (Array.isArray(parameter.value)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we still handling arrays here? Let __addDsNodes__ handle this. Also, I thought we were switching to object-only anyway.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, never mind, I see that we are just checking if it's a ds or not. That should be done by checking parameter.type == 'ds' instead.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok will update to check for parameter.type == 'ds'

Comment threadlib/ProgramCall.js Outdated
* @param {string} value
* @param {object} options
*/
__addDataNode__(name, type, value, options) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this function is needed. It should be rolled in to __addData__.

Comment threadlib/ProgramCall.js Outdated
* @param {array} ds
* @param {object} options
*/
__addDsNodes__(ds, options = {}) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this function is needed. It should be rolled in to __addData__.

@abmusse
abmusse requested a review from kadlerMarch 25, 2020 00:32
Comment threadlib/ProgramCall.js
Comment threadtest/unit/ProgamCallUnit.js Outdated
const { ProgramCall } = require('../../lib/itoolkit');

// now in this format
// [name, type, value, options]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is outdated with the latest changes

Comment threadtest/unit/ProgamCallUnit.js Outdated
});

pgm.addParam(outBuf, { io: 'out' });
pgm.addParam({ fields: outBuf, io: 'out', type: 'ds' });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer the fields go last; seems most sensible to me.

Comment threadtest/unit/ProgamCallUnit.js Outdated

pgm.addParam(params, { name: 'inds', by: 'val', io: 'both' });
pgm.addParam({
fields: params, type: 'ds', name: 'inds', by: 'val', io: 'both',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer to see attribute order as name, then type, then the rest. fields probably makes most sense to go last

@abmusse
abmusse requested a review from kadlerMarch 25, 2020 18:19
@kadler
kadler merged commit 376cc5a into IBM:masterMar 25, 2020
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Add Internal Function to handle adding Data Structure Parameters

2 participants

@abmusse@kadler