<commit_before>Sky.ui = Sky.ui || {};

/// Give the focus to the first element that matches the given
/// selector. If no elements match the selector, wait until one does
/// (checking every time we update an element through a reactive
/// template, renderList, etc), and then move the focus to it. In the
/// latter case, if there's a subsequent call to Sky.ui.focus before
/// the element is found, cancel the earlier call.
///
/// XXX XXX this doesn't help the (very reasonable) case where the
/// user calls a template function, then inserts the element in the
/// dom themselves..
Sky.ui.focus = function (selector) {
  Sky.ui._focus_goal = selector;
  Sky.ui._tryFocus();
};

Sky.ui._focus_goal = null;
Sky.ui._tryFocus = function () {
  if (Sky.ui._focus_goal) {
    // XXX jquery dependency
    var elt = $(Sky.ui._focus_goal)[0];
    if (elt) {
      elt.focus();
      Sky.ui._focus_goal = null;
    }
  }
};

/// Render some HTML, resulting in a DOM node, which is
/// returned. Update that DOM node in place when any of the rendering
/// dependencies change. (The tag name of the node returned from the
/// template mustn't change -- it must not be a function of any
/// dependencies.)
///
/// 'what' may be a function (which will be called and should return
/// an element), or a string (interpreted, for now, as a _ template),
/// or an element/jQuery result set (to use the DOM as a _ template)
///
/// If 'what' is a function, instead of returning a single element, it
/// is also allowed to return an array of elements. In this case, on
/// rerendering, it must still return an array, and the number and tag
/// names of the elements in the array must not change.
///
/// 'events' is optional. if given, takes the same kind of event map
/// as renderLive. If 'what' is a function and returns an array, the
/// event map will be applied to each element in the array.
///
/// 'event_data' will be passed to events when they fire, as their
/// object data agument.
///
/// render() may be called recursively (that is, 'what' can call
/// render.) when this happens, a change to a dependency in the inner
/// render() won't cause the stuff in the outer render() to be
/// re-evaluated, so it serves as a recomputation fence.
///
/// XXX refactor renderList to make it use this?
/// XXX need to provide a way to stop the updating and let GC happen!!!
/// XXX remove underscore template support.. it's only going to hurt you
Sky.ui.render = function (what, events, event_data) {
  var render;
  if (typeof(what) === 'object') {
    if (('$' in window) && (element instanceof $))
      what = what[0]; // allow jQuery result set
    if (what instanceof Element)
      what = $(template).html();
  }
  if (typeof(what) === 'string') {
    // XXX allow template to return multiple objects (changing the
    // signature of render() how?)
    var compiled_template = _.template(what);
    render = function (obj) {return $(what(obj))[0];};
  } else if (what instanceof Function)
    render = what;
  else
    throw new Error("Unrecognized template/renderer type");

  var result = null;
  var update = function () {
    var new_result = Sky.deps.captureDependencies(render, update);<commit_msg>Remove Sky.ui support for underscore templates<commit_after>Sky.ui = Sky.ui || {};

/// Give the focus to the first element that matches the given
/// selector. If no elements match the selector, wait until one does
/// (checking every time we update an element through a reactive
/// template, renderList, etc), and then move the focus to it. In the
/// latter case, if there's a subsequent call to Sky.ui.focus before
/// the element is found, cancel the earlier call.
///
/// XXX XXX this doesn't help the (very reasonable) case where the
/// user calls a template function, then inserts the element in the
/// dom themselves..
Sky.ui.focus = function (selector) {
  Sky.ui._focus_goal = selector;
  Sky.ui._tryFocus();
};

Sky.ui._focus_goal = null;
Sky.ui._tryFocus = function () {
  if (Sky.ui._focus_goal) {
    // XXX jquery dependency
    var elt = $(Sky.ui._focus_goal)[0];
    if (elt) {
      elt.focus();
      Sky.ui._focus_goal = null;
    }
  }
};

/// Render some HTML, resulting in a DOM node, which is
/// returned. Update that DOM node in place when any of the rendering
/// dependencies change. (The tag name of the node returned from the
/// template mustn't change -- it must not be a function of any
/// dependencies.)
///
/// render_func should return either a single DOM element, or an array
/// of elements. In the latter case, on rerendering, it must still
/// return an array, and the number and tag names of the elements in
/// the array must not change.
///
/// 'events' is optional. if given, takes the same kind of event map
/// as renderLive. If render_func retruns an array, the event map will
/// be applied to each element in the array. If 'event_data' is
/// provided, it will be passed to events when they fire, as their
/// object data agument.
///
/// render() may be called recursively (that is, 'what' can call
/// render.) when this happens, a change to a dependency in the inner
/// render() won't cause the stuff in the outer render() to be
/// re-evaluated, so it serves as a recomputation fence.
///
/// XXX refactor renderList to make it use this?
/// XXX need to provide a way to stop the updating and let GC happen!!!
/// XXX remove underscore template support.. it's only going to hurt you
Sky.ui.render = function (render_func, events, event_data) {
  var result = null;
  var update = function () {
    var new_result = Sky.deps.captureDependencies(render_func, update);
{'fraction_non_alphanumeric': 0.11662222222222222, 'fraction_numerical': 0.0007111111111111111, 'mean_word_length': 3.007122507122507, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '208146', 'n_tokens_mistral': 1586, 'n_tokens_neox': 1537, 'n_words': 773}