jsguy / mithril.sugartags

Sugar for mithril templating system
MIT License
20 stars 1 forks source link

Optimise to use mithril cache #5

Closed jsguy closed 9 years ago

jsguy commented 9 years ago

Using:

m('.item')

is more optimal than using:

m('div', {class:'item'})

Because in the first case Mithirl will clone a div node with the class attribute already set while in the second it will clone a generic div and then waste time adding the class attribute

See if we can optimise this.

Originally from: https://github.com/jsguy/misojs/issues/12

Mithril keeps a cache of created nodes indexed by the first argument to the m method. The more constant attributes you can pile up in the first argument, the best.

This: m('.item') is best than m('div', {class:'item'}) because in the first case Mithirl will clone a div node with the class attribute already set while in the second it will clone a generic div and then waste time adding the class attribute.