Skip to content

Commit

Permalink
Merge branch 'template-variable-parameter'
Browse files Browse the repository at this point in the history
  • Loading branch information
jgonggrijp committed Mar 14, 2021
2 parents 798eafa + 7e3d404 commit bf5a0ed
Show file tree
Hide file tree
Showing 20 changed files with 345 additions and 243 deletions.
2 changes: 1 addition & 1 deletion docs/modules/_setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ <h1>_setup.js</h1>

</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">var</span> VERSION = <span class="hljs-string">'1.12.0'</span>;</pre></div></div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">var</span> VERSION = <span class="hljs-string">'1.12.1'</span>;</pre></div></div>

</li>

Expand Down
50 changes: 34 additions & 16 deletions docs/modules/debounce.html
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ <h1>debounce.js</h1>
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> restArguments <span class="hljs-keyword">from</span> <span class="hljs-string">'./restArguments.js'</span>;
<span class="hljs-keyword">import</span> delay <span class="hljs-keyword">from</span> <span class="hljs-string">'./delay.js'</span>;</pre></div></div>
<span class="hljs-keyword">import</span> now <span class="hljs-keyword">from</span> <span class="hljs-string">'./now.js'</span>;</pre></div></div>

</li>

Expand All @@ -869,29 +869,47 @@ <h1>debounce.js</h1>
</div>

<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">debounce</span>(<span class="hljs-params">func, wait, immediate</span>) </span>{
<span class="hljs-keyword">var</span> timeout, result;
<span class="hljs-keyword">var</span> timeout, previous, args, result, context;

<span class="hljs-keyword">var</span> later = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">context, args</span>) </span>{
timeout = <span class="hljs-literal">null</span>;
<span class="hljs-keyword">if</span> (args) result = func.apply(context, args);
<span class="hljs-keyword">var</span> later = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-keyword">var</span> passed = now() - previous;
<span class="hljs-keyword">if</span> (wait &gt; passed) {
timeout = <span class="hljs-keyword">set</span><span class="hljs-title">Timeout</span>(<span class="hljs-params">later, wait - passed</span>);
} <span class="hljs-title">else</span> {
timeout = <span class="hljs-literal">null</span>;
<span class="hljs-keyword">if</span> (!immediate) result = func.apply(context, args);</pre></div></div>

</li>


<li id="section-3">
<div class="annotation">

<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<p>This check is needed because <code>func</code> can recursively invoke <code>debounced</code>.</p>

</div>

<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (!timeout) args = context = <span class="hljs-literal">null</span>;
}
};

<span class="hljs-keyword">var</span> debounced = restArguments(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">args</span>) </span>{
<span class="hljs-keyword">if</span> (timeout) clearTimeout(timeout);
<span class="hljs-keyword">if</span> (immediate) {
<span class="hljs-keyword">var</span> callNow = !timeout;
<span class="hljs-keyword">var</span> debounced = restArguments(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">_args</span>) </span>{
context = <span class="hljs-keyword">this</span>;
args = _args;
previous = now();
<span class="hljs-keyword">if</span> (!timeout) {
timeout = <span class="hljs-keyword">set</span><span class="hljs-title">Timeout</span>(<span class="hljs-params">later, wait</span>);
<span class="hljs-title">if</span> (<span class="hljs-params">callNow</span>) <span class="hljs-title">result</span> = <span class="hljs-title">func</span>.<span class="hljs-title">apply</span>(<span class="hljs-params">this, args</span>);
} <span class="hljs-title">else</span> {
timeout = delay(later, wait, <span class="hljs-keyword">this</span>, args);
<span class="hljs-title">if</span> (<span class="hljs-params">immediate</span>) <span class="hljs-title">result</span> = <span class="hljs-title">func</span>.<span class="hljs-title">apply</span>(<span class="hljs-params">context, args</span>);
}

<span class="hljs-keyword">return</span> result;
<span class="hljs-title">return</span> <span class="hljs-title">result</span>;
});

debounced.cancel = <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-title">debounced</span>.<span class="hljs-title">cancel</span> = <span class="hljs-title">function</span>() {
clearTimeout(timeout);
timeout = <span class="hljs-literal">null</span>;
timeout = args = context = <span class="hljs-literal">null</span>;
};

<span class="hljs-keyword">return</span> debounced;
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ <h1 id="named-exports">Named Exports</h1>
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">&#182;</a>
</div>
<pre><code>Underscore.js <span class="hljs-number">1.12</span><span class="hljs-number">.0</span>
<pre><code>Underscore.js <span class="hljs-number">1.12</span><span class="hljs-number">.1</span>
<span class="hljs-attr">https</span>:<span class="hljs-comment">//underscorejs.org</span>
(c) <span class="hljs-number">2009</span><span class="hljs-number">-2020</span> Jeremy Ashkenas, DocumentCloud and Investigative Reporters &amp; Editors
Underscore may be freely distributed under the MIT license.</code></pre>
Expand Down
20 changes: 14 additions & 6 deletions docs/modules/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,9 @@ <h1>template.js</h1>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">escapeChar</span>(<span class="hljs-params">match</span>) </span>{
<span class="hljs-keyword">return</span> <span class="hljs-string">'\\'</span> + escapes[match];
}</pre></div></div>
}

<span class="hljs-keyword">var</span> bareIdentifier = <span class="hljs-regexp">/^\s*(\w|\$)+\s*$/</span>;</pre></div></div>

</li>

Expand Down Expand Up @@ -980,7 +982,12 @@ <h1>template.js</h1>

<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> match;
});
source += <span class="hljs-string">"';\n"</span>;</pre></div></div>
source += <span class="hljs-string">"';\n"</span>;

<span class="hljs-keyword">var</span> argument = settings.variable;
<span class="hljs-keyword">if</span> (argument) {
<span class="hljs-keyword">if</span> (!bareIdentifier.test(argument)) <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Error</span>(argument);
} <span class="hljs-keyword">else</span> {</pre></div></div>

</li>

Expand All @@ -995,15 +1002,17 @@ <h1>template.js</h1>

</div>

<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (!settings.variable) source = <span class="hljs-string">'with(obj||{}){\n'</span> + source + <span class="hljs-string">'}\n'</span>;
<div class="content"><div class='highlight'><pre> source = <span class="hljs-string">'with(obj||{}){\n'</span> + source + <span class="hljs-string">'}\n'</span>;
argument = <span class="hljs-string">'obj'</span>;
}

source = <span class="hljs-string">"var __t,__p='',__j=Array.prototype.join,"</span> +
<span class="hljs-string">"print=function(){__p+=__j.call(arguments,'');};\n"</span> +
source + <span class="hljs-string">'return __p;\n'</span>;

<span class="hljs-keyword">var</span> render;
<span class="hljs-keyword">try</span> {
render = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(settings.variable || <span class="hljs-string">'obj'</span>, <span class="hljs-string">'_'</span>, source);
render = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Function</span>(argument, <span class="hljs-string">'_'</span>, source);
} <span class="hljs-keyword">catch</span> (e) {
e.source = source;
<span class="hljs-keyword">throw</span> e;
Expand All @@ -1026,8 +1035,7 @@ <h1>template.js</h1>

</div>

<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">var</span> argument = settings.variable || <span class="hljs-string">'obj'</span>;
template.source = <span class="hljs-string">'function('</span> + argument + <span class="hljs-string">'){\n'</span> + source + <span class="hljs-string">'}'</span>;
<div class="content"><div class='highlight'><pre> template.source = <span class="hljs-string">'function('</span> + argument + <span class="hljs-string">'){\n'</span> + source + <span class="hljs-string">'}'</span>;

<span class="hljs-keyword">return</span> template;
}</pre></div></div>
Expand Down
Loading

0 comments on commit bf5a0ed

Please sign in to comment.