nodejs-itoolkit icon indicating copy to clipboard operation
nodejs-itoolkit copied to clipboard

Added types implementation

Open alexandrahrastnik opened this issue 6 years ago • 5 comments

Suggested fix for #75

Signed-off-by: HRASTNIK Patrick Ing [email protected]

alexandrahrastnik avatar Aug 08 '19 07:08 alexandrahrastnik

:wave: Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

github-actions[bot] avatar Feb 08 '20 00:02 github-actions[bot]

Would be good to get this merged. @patrickhrastnik, not sure if you have time to resolve the conflicts otherwise @abmusse if you want to pull the changes in to a new PR and get it merged that would be great.

kadler avatar Jan 14 '21 22:01 kadler

One thing that I was thinking about that would impact this, is it would be really nice to have a varchar type, but that would require having the function/object return both the XMLSERVICE type as well as the varying="XX" attribute.

I think this could be done by having the function return an object with the attributes and using the javascript spread operator:

# old way
program.addParam({ type: '10A', varying: '4', value: 'Gill' });

function varchar(len) {
  return { type: len.toString() + 'a', varying: '2' }
}
function longvarchar(len) {
  return { type: len.toString() + 'a', varying: '4' }
}

program.addParam({ ...longvarchar(10), value: 'Gill' });

If we did that, it might also make sense to use camel case on the names:

  • Integer
  • Char
  • Varchar
  • LongVarchar
  • etc

kadler avatar Jan 14 '21 22:01 kadler

One thing that I was thinking about that would impact this, is it would be really nice to have a varchar type, but that would require having the function/object return both the XMLSERVICE type as well as the varying="XX" attribute.

I think this could be done by having the function return an object with the attributes and using the javascript spread operator:

# old way
program.addParam({ type: '10A', varying: '4', value: 'Gill' });

function varchar(len) {
  return { type: len.toString() + 'a', varying: '2' }
}
function longvarchar(len) {
  return { type: len.toString() + 'a', varying: '4' }
}

program.addParam({ ...longvarchar(10), value: 'Gill' });

If we did that, it might also make sense to use camel case on the names:

  • Integer
  • Char
  • Varchar
  • LongVarchar
  • etc

Nice! The spread operator works out cleanly in this situation. I just tested it out in sample script:

function LongVarChar(len) {
  return { type: len.toString() + 'A', varying: '4' }
}

function addParam(param) {
  console.log(param)
}

addParam({ type: '10A', varying: '2', value: 'Gill' });
addParam({ ...LongVarChar(10), value: 'Gill' })

Output

{ type: '10A', varying: '2', value: 'Gill' }
{ type: '10A', varying: '4', value: 'Gill' }

The use of camel case be to minimize confusion for the reader? I'm pretty sure the linter will complain but we can work around that.

abmusse avatar Jan 15 '21 02:01 abmusse

:wave: Hi! This pull request has been marked stale due to inactivity. If no further activity occurs, it will automatically be closed.

github-actions[bot] avatar Feb 15 '21 00:02 github-actions[bot]