Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 40
refactor: ProgramCall.addParam to accept an object#139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
381bce8
refactor: ProgramCall.addParam to accept an object
abmusse 4529380
refactor: iPgm.addParam to call ProgramCall.addParam with an object
abmusse 2fa2ed6
test: Update ProgramCallUnit with addParam changes
abmusse 4908bb2
fixup! refactor: ProgramCall.addParam to accept an object
abmusse 955d04e
fixup! fixup! refactor: ProgramCall.addParam to accept an object
abmusse 5f929ed
fixup! refactor: ProgramCall.addParam to accept an object
abmusse d86b478
fixup! refactor: ProgramCall.addParam to accept an object
abmusse dee1089
fixup! refactor: iPgm.addParam to call ProgramCall.addParam with an o…
abmusse 5d2ee26
fixup! test: Update ProgramCallUnit with addParam changes
abmusse 03058e2
fixup! fixup! test: Update ProgramCallUnit with addParam changes
abmusse af333b9
fixup! refactor: ProgramCall.addParam to accept an object
abmusse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -16,6 +16,8 @@ | ||
| // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| /* eslint-disable no-underscore-dangle */ | ||
| class ProgramCall { | ||
| /** | ||
| * @description creates a new ProgramCall object | ||
| @@ -31,59 +33,62 @@ class ProgramCall { | ||
| } | ||
| /** | ||
| * @description adds a parameter to the program XML | ||
| * @param {string | array} data | ||
| * @param {string} [type] | ||
| * @param {object} options | ||
| * @param {*} inDs | ||
| */ | ||
| addParam(data, type, options, inDs = null) { | ||
| let opt; | ||
| // DS element has no 'type', so if the second param 'type' is an Object, then it is the options. | ||
| if (Array.isArray(data)) { | ||
| opt = type; | ||
| } else { | ||
| opt = options; | ||
| if (type === undefined) { | ||
| throw new Error('Specifying the parameter type is required.'); | ||
| } | ||
| } | ||
| if (!inDs) { // In recursive mode, if it is an element in DS, then no <parm> or </parm> needed. | ||
| this.xml += '<parm'; | ||
| if (opt && typeof opt === 'object') { // append <param> options | ||
| if (opt.io) { this.xml += ` io='${opt.io}'`; } | ||
| if (opt.by) { this.xml += ` by='${opt.by}'`; } | ||
| } | ||
| this.xml += '>'; | ||
| } | ||
| if (Array.isArray(data)) { // If it is a struct parameter, recursively parse its children. | ||
| * Internal function to handle ds and data within <parm> node | ||
| * There is an open propsal to add private methods to JS. | ||
| * https://github.com/tc39/proposal-private-methods | ||
| * We should update to use private methods in the future. | ||
| * @param {object} data | ||
| */ | ||
| __addData__(data = {}) { | ||
| if (data.type === 'ds') { | ||
| this.xml += '<ds'; | ||
| if (opt && typeof opt === 'object') { // append <ds> options | ||
| if (opt.dim) { this.xml += ` dim='${opt.dim}'`; } | ||
| if (opt.dou) { this.xml += ` dou='${opt.dou}'`; } | ||
| if (opt.len) { this.xml += ` len='${opt.len}'`; } | ||
| if (opt.data) { this.xml += ` data='${opt.data}'`; } | ||
| } | ||
| // append <ds> options | ||
| if (data.name) { this.xml += ` name='${data.name}'`; } | ||
| if (data.dim) { this.xml += ` dim='${data.dim}'`; } | ||
| if (data.dou) { this.xml += ` dou='${data.dou}'`; } | ||
| if (data.len) { this.xml += ` len='${data.len}'`; } | ||
| if (data.data) { this.xml += ` data='${data.data}'`; } | ||
| this.xml += '>'; | ||
| for (let i = 0; i < data.length; i += 1) { | ||
| this.addParam(data[i][0], data[i][1], data[i][2], true); | ||
| for (let i = 0; i < data.fields.length; i += 1) { | ||
| this.__addData__(data.fields[i]); | ||
| } | ||
| this.xml += '</ds>'; | ||
| } else { // A simple parameter | ||
| this.xml += `<data type='${type}'`; | ||
| if (opt && typeof opt === 'object') { // append <data> options | ||
| Object.keys(opt).forEach((key) => { | ||
| this.xml += ` ${key}='${opt[key]}'`; | ||
| }); | ||
| } | ||
| this.xml += `>${data}</data>`; | ||
| } else { | ||
| this.xml += `<data type='${data.type}'`; | ||
| // append <data> options | ||
| if (data.name) { this.xml += ` name='${data.name}'`; } | ||
| if (data.varying) { this.xml += ` varying='${data.varying}'`; } | ||
| if (data.enddo) { this.xml += ` enddo='${data.enddo}'`; } | ||
| if (data.setlen) { this.xml += ` setlen='${data.setlen}'`; } | ||
| if (data.offset) { this.xml += ` offset='${data.offset}'`; } | ||
| if (data.hex) { this.xml += ` hex='${data.hex}'`; } | ||
| if (data.trim) { this.xml += ` trim='${data.trim}'`; } | ||
| if (data.next) { this.xml += ` next='${data.next}'`; } | ||
| this.xml += `>${data.value}</data>`; | ||
| } | ||
| } | ||
| if (!inDs) { // In recursive mode, if it is an element in DS, then no <parm> or </parm> needed. | ||
| this.xml += '</parm>'; | ||
| /** | ||
| * @description adds a parameter to the program XML | ||
| * @param {object} parmeter | ||
| */ | ||
| addParam(parameter = {}) { | ||
| if (typeof parameter !== 'object') { | ||
| throw new Error('Expected the first parameter to be an object'); | ||
| } | ||
| if (parameter.type === undefined) { | ||
| throw new Error('Expected \'type\' key on the parameter object'); | ||
| } | ||
| this.xml += '<parm'; | ||
| if (parameter.name) { this.xml += ` name='${parameter.name}'`; } | ||
| if (parameter.io) { this.xml += ` io='${parameter.io}'`; } | ||
| if (parameter.by) { this.xml += ` by='${parameter.by}'`; } | ||
| this.xml += '>'; | ||
| this.__addData__(parameter); | ||
kadler marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| this.xml += '</parm>'; | ||
| } | ||
| /** | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.