batiste / pug-vdom

PUG template to HyperScript Virtual DOM
MIT License
18 stars 6 forks source link

Generated code is bloated and difficult to read #11

Closed batiste closed 7 years ago

batiste commented 7 years ago

[].reduce(function(finalObj, currObj){ for (var propName in currObj) {finalObj[propName] = propName === "class" ? (finalObj[propName] ? finalObj[propName].concat(currObj[propName]) : [currObj[propName]]) : currObj[propName]; } return finalObj; }, {

This code is repeating itself again and again. I have 2 suggestions:

  1. Introduce a function in the generated code and use it
  2. Do not generate this code on a empty array?
batiste commented 7 years ago

@Gryphon Myers what do you think of this?

gryphonmyers commented 7 years ago

Yes, sorry I did have cleaning this up on my mental to-do list. Both good suggestions, and using template literals would also allow for more consistent indentation. I will improve this when I get a moment.

gryphonmyers commented 7 years ago

Introduce a function in the generated code and use it

Thinking about this suggestion, it occurred to me that we could reduce bloat overall by introducing a small runtime library. How do you feel about that idea?

batiste commented 7 years ago

@gryphonmyers yeah I would introduce a runtime lib, that sounds like a great idea. Maybe use an external file for this so can be tested easily and independently.

batiste commented 7 years ago

Thanks for the great contribution and tests 👍