Skip to content

Warn about reusing object within attrs? #2826

@gjmcn

Description

@gjmcn

Mithril.js version: 2.2.2

Browser and OS: Chrome, Windows 10

The following had me confused for some time:

let style = {
  width: '100px',
  height: '30px',
  background: '#4682B4',
};

m.mount(document.body, {
  view: () => [
    m('input', {
      type: 'range',
      min: 1,
      max: 200,
      oninput: function() { style.width = `${this.value}px` }
    }),
    // m('div', { style })            // does not trigger redraw
    // m('div', { style: style })     // does not trigger redraw
    m('div', { style: { ...style }})  // works
  ]
});  

I think the issue is that the // does not trigger redraw versions are resuing an object within attrs and I guess this is not allowed? If so, the problem is that (unlike when reusing attrs itself) Mithril does not give a warning for the above case. Perhaps it should? Or if this is too inefficient, maybe this could be covered more in the docs? - apologies if it is and I missed it!

Metadata

Metadata

Assignees

Labels

Area: CoreFor anything dealing with Mithril core itselfType: EnhancementFor any feature request or suggestion that isn't a bug fix

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions