bitty installation snippets examples documentation q&a

snippets

forward an element as a sender

waiting
  • Forward an element to another function in the sender position (i.e. the second argument)
  • This allows initialization functions to run other functions that require a sender and would otherwise require a click (or some other interaction) on the sender element on the page.
  • For example, in this snippet, `b = { init: "initForwardSender" } simulates clicking the button so the time gets updated when the page loads.

html

<div data-r="receiveSender">waiting</div>
<button data-s="receiveSender" data-r="initForwardSender" data-key="from forwared sender">
  Update Time
</button>

javascript

export const b = {
  init: "initForwardSender",
};

export function initForwardSender(_, __, el) {
  b.forwardSender(el, "receiveSender");
}

export function receiveSender(_, sender, el) {
  el.innerHTML = `${sender.prop("key")} at ${b.time()}`;
}