question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Whenever we morph elements we should probs be copying over the events. From yo-yo:

// update-events.js
module.exports = [
  // attribute events (can be set with attributes)
  'onclick',
  'ondblclick',
  'onmousedown',
  'onmouseup',
  'onmouseover',
  'onmousemove',
  'onmouseout',
  'ondragstart',
  'ondrag',
  'ondragenter',
  'ondragleave',
  'ondragover',
  'ondrop',
  'ondragend',
  'onkeydown',
  'onkeypress',
  'onkeyup',
  'onunload',
  'onabort',
  'onerror',
  'onresize',
  'onscroll',
  'onselect',
  'onchange',
  'onsubmit',
  'onreset',
  'onfocus',
  'onblur',
  'oninput',
  // other common events
  'oncontextmenu',
  'onfocusin',
  'onfocusout'
]
// copy.js
  function copier (f, t) {
    // copy events:
    var events = opts.events || defaultEvents
    for (var i = 0; i < events.length; i++) {
      var ev = events[i]
      if (t[ev]) { // if new element has a whitelisted attribute
        f[ev] = t[ev] // update existing element
      } else if (f[ev]) { // if existing element has it and new one doesnt
        f[ev] = undefined // remove it from existing element
      }
    }
    // copy values for form elements
    if ((f.nodeName === 'INPUT' && f.type !== 'file') || f.nodeName === 'TEXTAREA' || f.nodeName === 'SELECT') {
      if (t.getAttribute('value') === null) t.value = f.value
    }
  }

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
yoshuawuytscommented, Sep 23, 2016

@kristoferjoseph looping should be rare tho; if we implement morphdom’s .isSameNode() trick then only the hot path will ever be looped for equal nodes only which even pessimistically isn’t that many nodes.

Optimistically it should be fine I think; doing the existing approach of yo-yo we’re already miles ahead of every rendering engine in terms of perf so I’m not too worried for real world perf, even though from a purist standpoint I wholly agree with what you’re saying - maybe mark it as something to revisit later?

1reaction
kristoferjosephcommented, Sep 23, 2016

Looks like you can copy over only the events being used by an element, but it requires looping over the elements keys. That may be faster than iterating over a longer list of event types, but I am not sure. https://github.com/kristoferjoseph/nanomorph/blob/master/morph.js#L16

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Automatically Copy Events From One Google ... - Zapier
Google makes it easy to share an entire calendar, but there's no obvious way to copy all your events from one calendar to...
Read more >
How to Copy or Import Google Calendars - Lifewire
To copy single events: Select event > pencil icon > More Actions in upper-right corner > Copy to. This article explains how to...
Read more >
How to Copy Events in Outlook Calendar
1. Launch Outlook and click the “Calendar” link at the bottom of the screen. · 2. Scroll to the date of the event...
Read more >
Element: copy event - Web APIs | MDN
The copy event fires when the user initiates a copy action through the browser's user interface. The event's default action is to copy...
Read more >
How to move, copy or duplicate Calendar events to another ...
Copy events to another calendar on Mac · 1) Either right-click on the event or click Edit from the menu bar and pick...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found