Setter on attr camel cases doesn't set the proper dashed attribute value.
opened this issue · comments
I found that the camel cased attribute wasn't setting the correct attribute name when you use camel casing. I made a change to the descriptor.set function in the onParse() method of the extensions
property of the xtag
object.
descriptor.set = function(val){
if (!descriptor._skip){console.log(val);
descriptor._skip = true;
var output;
// ***** descSet
if (descSet) output = descSet.call(this, val);
// START OF EDIT [KIP OMAHA]
let a = prop.match(/[a-z]+(?=[A-Z])/g)[0];
let b = prop.match(/[A-Z][a-z]+/g)[0].toLowerCase();
prop = a+"-"+b;
// END OF EDIT [KIP OMAHA]
typeSet.call(this, prop, typeof output == 'undefined' ? val : output);
descriptor._skip = null;
}
}
This seems to work but it needs testing of course.
Would you like a pull request or would you like an example of the bug?
Maybe, prop = a+"-"+b
[THIRD LINE CHANGE]
should be changed to, prop = a+"-"+b || prop
-EDIT
It also wouldn't capture something like, myGnarlyAttribute
, I'm fairly certain.
Maybe make a function to pass the prop value to get scrubbed and returned?
Here is a function I made for compatibility with longer dash attributes like my-gnarly-attr-is-here
.
function camels(p){
var silly = "";
if(/[a-z]+(?=[A-Z])/g.test(p) === true) {
let i = p.match(/[a-z]+(?=[A-Z])/g);
let m = p.match(/[A-Z][a-z]+/g);
for(var x=0; x<i.length; x++){ silly+=i[x]+"-"+m[x]+"-"; }
silly = silly.replace(/\-$/g,""); // EDIT: It probably doesn't need the `g` flag
return silly;
}
else return p;
}
Jasmine test link: https://kipomaha.github.io/x-tag-setup/core-tests/basic/index.html#
Branch build jasmine test link: https://kipomaha.github.io/x-tag-setup/pkgs/jasmine-tests/dashboard_jasmine.html
I've got another push to commit for some more render testing.
I just fixed this and tagged a new alpha, 2.0.4-alpha
I saw it pop up in my feed, thanks