Elements with an [up-hungry]
attribute are updated whenever the server
sends a matching element, even if the element isn't targeted.
Hungry elements are optional in the same way as :maybe
targets.
When an [up-hungry]
element does not match in the server response, the element will not be updated,
but no error is thrown.
Common use cases for [up-hungry]
are elements that live in the application layout,
outside of the fragment that is typically being targeted. Examples include:
Instead of explicitly including such elements in every target selector
(e.g. .content, .unread-messages:maybe
) we can mark the element as [up-hungry]
:
<div class="unread-messages" up-hungry>
You have no unread messages
</div>
An selector for the hungry element (.unread-messages
) will be added to target selectors automatically.
When an [up-hungry]
fragment piggy-backs on another fragment update, Unpoly
will derive a target selector for the hungry element.
For this to work the hungry element must have an identifying attribute,
like an [id]
or a unique [class]
attribute.
When no good target can be derived, the hungry element is excluded from the update.
By default only hungry elements on the targeted layer are updated.
To match a hungry element when updating other layers, set an [up-if-layer]
attribute.
For example, a hungry element with [up-if-layer="subtree"]
will piggy-back on render passes for both
its own layer and any overlay covering it.
When Unpoly renders new content, each element in that content can only be inserted once. When multiple hungry elements conflict with each other or with the the primary render target, that conflict is resolved using the following rules:
By default hungry fragments are processed for all updates of the current layer. You can disable the processing of hungry fragments using one of the following methods:
{ useHungry: false }
option will not process any hungry fragments.[up-use-hungry="false"]
attribute on a link or form will not update hungry fragments when the element is activated.up:fragment:hungry
event will prevent the hungry fragment
from being updated.event.preventDefault()
in an [up-on-hungry]
attribute handler will prevent the hungry fragment
from being updated.Only piggy-back on updates on layers that match the given layer reference.
Relative references like 'parent'
or 'child'
will be resolved in relation to the hungry element's layer.
To match a hungry element when updating one of multiple layers, separate the references using and or
delimiter.
For example, 'current or child'
will match for updates on either the hungry element's layer, or
its direct child.
To match a hungry element when updating any layer, set this attribute to 'any'
.
Code to run before this element is included in a fragment update.
Calling event.preventDefault()
will prevent the hungry fragment
from being updated.
For instance, you want to auto-update an hungry navigation bar, but only if we're changing history entries:
<nav id="side-nav" up-hungry up-on-hungry="if (!renderOptions.history) event.preventDefault()">
...
</nav>
The code may use the variables event
(of type up:fragment:hungry
),
this
(the hungry element), newFragment
and renderOptions
.
The animated transition to apply when this element is updated.
The duration of the transition or animation (in millisconds).
The timing function that accelerates the transition or animation.
See MDN documentation for a list of available timing functions.