Edit this page

up.radio up:fragment:hungry
DOM event

This feature is experimental. Please share your experiences so we know what to keep or change.

Before an [up-hungry] is added to a render pass, a event up:fragment:hungry is emitted on the element.

Preventing hungry elements from being updated

You may prevent the up:fragment:hungry event to exclude an hungry element from the render pass. Use this to define arbitrary conditions for when an hungry element should be updated.

For example, the following would update an hungry element only for render passes that update history:

element.addEventListener('up:fragment:hungry', function(event) {
  if (!event.renderOptions.history) event.preventDefault()
})

You may also define conditions based on the new element that a hungry element would be swapped with. The following would skip an update if the new element has a class .is-empty:

element.addEventListener('up:fragment:hungry', function(event) {
  if (event.newFragment.classList.contains('is-empty')) {
    event.preventDefault()
  }
})

Event properties

event.target Element

The hungry element that is about to be swapped.

event.newFragment Element

The fragment in the new content that this hungry element would be swapped with.

event.renderOptions Object

The render options for the current render pass.

event.preventDefault()

Prevents the hungry element from being targeted in the current render pass.