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
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.
Using:
m('.item')
is more optimal than using:
m('div', {class:'item'})
Because in the first case Mithirl will clone a
div
node with theclass
attribute already set while in the second it will clone a genericdiv
and then waste time adding theclass
attributeSee 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 thanm('div', {class:'item'})
because in the first case Mithirl will clone adiv
node with theclass
attribute already set while in the second it will clone a genericdiv
and then waste time adding theclass
attribute.