-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[WIP] Improved barcode options #171
base: master
Are you sure you want to change the base?
Conversation
@@ -4,6 +4,10 @@ class Barcode{ | |||
this.text = options.text || data; | |||
this.options = options; | |||
} | |||
|
|||
static options() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you think to make it as a property, but not as a function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it. The main reason why I wanted to make this a function is that it will make inheritance of options easier. If for all CODE128 codes have one option but we want to add additional options to that sub-symbology it can easily be done like follow.
static options() {
return Object.assign({}, super.options(), {
somenewoptions: {}
});
}
@@ -25,7 +25,9 @@ class ErrorHandler{ | |||
wrapBarcodeCall(func){ | |||
try{ | |||
var result = func(...arguments); | |||
this.api._options.valid(true); | |||
if (typeof this.api._options.valid !== 'undefined') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.api._options.valid !== undefined
should be enough, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, you can do it in old specs as I see (http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.1.3). But for a public library your way is better :)
|
||
// Convert an option to a specified type | ||
function convertOption(data, type) { | ||
if (type === 'string') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check type before:
if (typeof data !== type) {
// do conversions
}
return data;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type
is the type it should be converted TO, not the type it already is. Or I might have misunderstood this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example convertOption(10, 'number')
causes return parseInt(data, 10);
anyway. I suggest check type of data before and avoid any unnecessary conversion. Or I missed something :)
And please, do not forget about options for CODE128 :) |
Of course I will not 😉 I just added EAN to test with and there is a lot of other options thats need to be added. |
This is a WIP of how I want to implement barcode specific options. It does also allow for the awful
optionsFromStrings.js
to be removed.It is not done and does not yet work fully, but what do you think of the general idea @SanichKotikov ?