MCPcopy
hub / github.com/winjs/winjs / interpretedRender

Function interpretedRender

src/js/WinJS/BindingTemplate.js:41–154  ·  view source on GitHub ↗
(template, dataContext, container)

Source from the content-addressed store, hash-verified

39 /// <resource type="css" src="//$(TARGET_DESTINATION)/css/ui-dark.css" shared="true" />
40 Template: _Base.Namespace._lazy(function () {
41 function interpretedRender(template, dataContext, container) {
42 _WriteProfilerMark("WinJS.Binding:templateRender" + template._profilerMarkIdentifier + ",StartTM");
43
44 if (++template._counter === 1 && (template.debugBreakOnRender || Template._debugBreakOnRender)) {
45 debugger; // jshint ignore:line
46 }
47
48 var workPromise = Promise.wrap();
49 var d = container || _Global.document.createElement(template.element.tagName);
50
51 _ElementUtilities.addClass(d, "win-template");
52 _ElementUtilities.addClass(d, "win-loading");
53 var that = template;
54 function done() {
55 _ElementUtilities.removeClass(d, "win-loading");
56 _WriteProfilerMark("WinJS.Binding:templateRender" + template._profilerMarkIdentifier + ",StopTM");
57 return extractedChild || d;
58 }
59 var initial = d.children.length;
60 var element;
61 var extractedChild;
62 var dispose = function () {
63 var bindings = _ElementUtilities.data(d).winBindings;
64 if (bindings) {
65 bindings.forEach(function (item) {
66 item.cancel();
67 });
68 }
69 workPromise.cancel();
70 };
71 if (template.extractChild) {
72 element = Fragments.renderCopy(that.href || that.element, _Global.document.createElement(that.element.tagName)).then(function (frag) {
73 var child = frag.firstElementChild;
74 extractedChild = child;
75 _Dispose.markDisposable(child, dispose);
76 d.appendChild(child);
77 return child;
78 });
79 } else {
80 _Dispose.markDisposable(d, dispose);
81 element = Fragments.renderCopy(that.href || that.element, d);
82 }
83 var renderComplete = element.
84 then(function Template_renderImpl_renderComplete_then() {
85 var work;
86 // If no existing children, we can do the faster path of just calling
87 // on the root element...
88 //
89 if (initial === 0) {
90 work = function (f, a, b, c) { return f(extractedChild || d, a, b, c); };
91 } else {
92 // We only grab the newly added nodes (always at the end)
93 // and in the common case of only adding a single new element
94 // we avoid the "join" overhead
95 //
96 var all = d.children;
97 if (all.length === initial + 1) {
98 work = function (f, a, b, c) { return f(all[initial], a, b, c); };

Callers 1

BindingTemplate.jsFile · 0.85

Calls 10

wrapMethod · 0.80
createElementMethod · 0.80
appendChildMethod · 0.80
completeFunction · 0.70
doneFunction · 0.70
addClassMethod · 0.65
thenMethod · 0.65
pushMethod · 0.65
forEachMethod · 0.65
joinMethod · 0.65

Tested by

no test coverage detected