scrawl-canvas
Version:
Version 8.9.4 - 19 Nov 2022
946 lines (608 loc) • 41.5 kB
HTML
<html>
<head>
<title>Asset mixin</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="../../docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="../core/animationloop.html">
./source/core/animationloop.js
</a>
<a class="source" href="../core/document.html">
./source/core/document.js
</a>
<a class="source" href="../core/events.html">
./source/core/events.js
</a>
<a class="source" href="../core/init.html">
./source/core/init.js
</a>
<a class="source" href="../core/library.html">
./source/core/library.js
</a>
<a class="source" href="../core/random-seed.html">
./source/core/random-seed.js
</a>
<a class="source" href="../core/snippets.html">
./source/core/snippets.js
</a>
<a class="source" href="../core/userInteraction.html">
./source/core/userInteraction.js
</a>
<a class="source" href="../core/utilities.html">
./source/core/utilities.js
</a>
<a class="source" href="../factory/action.html">
./source/factory/action.js
</a>
<a class="source" href="../factory/anchor.html">
./source/factory/anchor.js
</a>
<a class="source" href="../factory/animation.html">
./source/factory/animation.js
</a>
<a class="source" href="../factory/bezier.html">
./source/factory/bezier.js
</a>
<a class="source" href="../factory/block.html">
./source/factory/block.js
</a>
<a class="source" href="../factory/canvas.html">
./source/factory/canvas.js
</a>
<a class="source" href="../factory/cell.html">
./source/factory/cell.js
</a>
<a class="source" href="../factory/cog.html">
./source/factory/cog.js
</a>
<a class="source" href="../factory/color.html">
./source/factory/color.js
</a>
<a class="source" href="../factory/conicGradient.html">
./source/factory/conicGradient.js
</a>
<a class="source" href="../factory/coordinate.html">
./source/factory/coordinate.js
</a>
<a class="source" href="../factory/crescent.html">
./source/factory/crescent.js
</a>
<a class="source" href="../factory/element.html">
./source/factory/element.js
</a>
<a class="source" href="../factory/emitter.html">
./source/factory/emitter.js
</a>
<a class="source" href="../factory/filter.html">
./source/factory/filter.js
</a>
<a class="source" href="../factory/filterEngine-bluenoiseData.html">
./source/factory/filterEngine-bluenoiseData.js
</a>
<a class="source" href="../factory/filterEngine.html">
./source/factory/filterEngine.js
</a>
<a class="source" href="../factory/fontAttributes.html">
./source/factory/fontAttributes.js
</a>
<a class="source" href="../factory/gradient.html">
./source/factory/gradient.js
</a>
<a class="source" href="../factory/grid.html">
./source/factory/grid.js
</a>
<a class="source" href="../factory/group.html">
./source/factory/group.js
</a>
<a class="source" href="../factory/imageAsset.html">
./source/factory/imageAsset.js
</a>
<a class="source" href="../factory/line.html">
./source/factory/line.js
</a>
<a class="source" href="../factory/lineSpiral.html">
./source/factory/lineSpiral.js
</a>
<a class="source" href="../factory/loom.html">
./source/factory/loom.js
</a>
<a class="source" href="../factory/mesh.html">
./source/factory/mesh.js
</a>
<a class="source" href="../factory/net.html">
./source/factory/net.js
</a>
<a class="source" href="../factory/noiseAsset.html">
./source/factory/noiseAsset.js
</a>
<a class="source" href="../factory/oval.html">
./source/factory/oval.js
</a>
<a class="source" href="../factory/palette.html">
./source/factory/palette.js
</a>
<a class="source" href="../factory/particle.html">
./source/factory/particle.js
</a>
<a class="source" href="../factory/particleForce.html">
./source/factory/particleForce.js
</a>
<a class="source" href="../factory/particleHistory.html">
./source/factory/particleHistory.js
</a>
<a class="source" href="../factory/particleSpring.html">
./source/factory/particleSpring.js
</a>
<a class="source" href="../factory/particleWorld.html">
./source/factory/particleWorld.js
</a>
<a class="source" href="../factory/pattern.html">
./source/factory/pattern.js
</a>
<a class="source" href="../factory/phrase.html">
./source/factory/phrase.js
</a>
<a class="source" href="../factory/picture.html">
./source/factory/picture.js
</a>
<a class="source" href="../factory/polygon.html">
./source/factory/polygon.js
</a>
<a class="source" href="../factory/polyline.html">
./source/factory/polyline.js
</a>
<a class="source" href="../factory/quadratic.html">
./source/factory/quadratic.js
</a>
<a class="source" href="../factory/quaternion.html">
./source/factory/quaternion.js
</a>
<a class="source" href="../factory/radialGradient.html">
./source/factory/radialGradient.js
</a>
<a class="source" href="../factory/rawAsset.html">
./source/factory/rawAsset.js
</a>
<a class="source" href="../factory/rdAsset.html">
./source/factory/rdAsset.js
</a>
<a class="source" href="../factory/rectangle.html">
./source/factory/rectangle.js
</a>
<a class="source" href="../factory/renderAnimation.html">
./source/factory/renderAnimation.js
</a>
<a class="source" href="../factory/shape.html">
./source/factory/shape.js
</a>
<a class="source" href="../factory/spiral.html">
./source/factory/spiral.js
</a>
<a class="source" href="../factory/spriteAsset.html">
./source/factory/spriteAsset.js
</a>
<a class="source" href="../factory/stack.html">
./source/factory/stack.js
</a>
<a class="source" href="../factory/star.html">
./source/factory/star.js
</a>
<a class="source" href="../factory/state.html">
./source/factory/state.js
</a>
<a class="source" href="../factory/tetragon.html">
./source/factory/tetragon.js
</a>
<a class="source" href="../factory/ticker.html">
./source/factory/ticker.js
</a>
<a class="source" href="../factory/tracer.html">
./source/factory/tracer.js
</a>
<a class="source" href="../factory/tween.html">
./source/factory/tween.js
</a>
<a class="source" href="../factory/unstackedElement.html">
./source/factory/unstackedElement.js
</a>
<a class="source" href="../factory/vector.html">
./source/factory/vector.js
</a>
<a class="source" href="../factory/videoAsset.html">
./source/factory/videoAsset.js
</a>
<a class="source" href="../factory/wheel.html">
./source/factory/wheel.js
</a>
<a class="source" href="anchor.html">
./source/mixin/anchor.js
</a>
<a class="source" href="asset.html">
./source/mixin/asset.js
</a>
<a class="source" href="assetAdvancedFunctionality.html">
./source/mixin/assetAdvancedFunctionality.js
</a>
<a class="source" href="assetConsumer.html">
./source/mixin/assetConsumer.js
</a>
<a class="source" href="base.html">
./source/mixin/base.js
</a>
<a class="source" href="cascade.html">
./source/mixin/cascade.js
</a>
<a class="source" href="delta.html">
./source/mixin/delta.js
</a>
<a class="source" href="displayShape.html">
./source/mixin/displayShape.js
</a>
<a class="source" href="dom.html">
./source/mixin/dom.js
</a>
<a class="source" href="entity.html">
./source/mixin/entity.js
</a>
<a class="source" href="filter.html">
./source/mixin/filter.js
</a>
<a class="source" href="mimic.html">
./source/mixin/mimic.js
</a>
<a class="source" href="path.html">
./source/mixin/path.js
</a>
<a class="source" href="pattern.html">
./source/mixin/pattern.js
</a>
<a class="source" href="pivot.html">
./source/mixin/pivot.js
</a>
<a class="source" href="position.html">
./source/mixin/position.js
</a>
<a class="source" href="shapeBasic.html">
./source/mixin/shapeBasic.js
</a>
<a class="source" href="shapeCurve.html">
./source/mixin/shapeCurve.js
</a>
<a class="source" href="shapePathCalculation.html">
./source/mixin/shapePathCalculation.js
</a>
<a class="source" href="styles.html">
./source/mixin/styles.js
</a>
<a class="source" href="tween.html">
./source/mixin/tween.js
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="section-1">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-1">§</a>
</div>
<h1 id="asset-mixin">Asset mixin</h1>
<p>The asset factories - <a href="../factory/imageAsset.html">ImageAsset</a>, <a href="../factory/spriteAsset.html">SpriteAsset</a>, and <a href="../factory/videoAsset.html">VideoAsset</a> - are wrappers around images and videos which can either be pulled from the current document (DOM-based assets) or fetched from the server using an URL address.</p>
<ul>
<li>Assets are used (consumed) by Picture entitys and Pattern styles.</li>
<li>This mixin adds functionality common to all three factories to them as part of their initialization.</li>
<li>The mixin is also used by the <a href="../factory/cell.html">Cell</a> factory, as <canvas> elements can be used by Picture entitys and Pattern styles as their image sources.</li>
</ul>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-2">§</a>
</div>
<p>Assets can be loaded into scrawl using dedicated import and create functions:</p>
<ul>
<li><code>scrawl.importImage</code></li>
<li><code>scrawl.importDomImage</code></li>
<li><code>scrawl.importDomVideo</code></li>
<li><code>scrawl.importVideo</code></li>
<li><code>scrawl.importMediaStream</code></li>
<li><code>scrawl.importSprite</code></li>
<li><code>scrawl.createImageFromCell</code></li>
<li><code>scrawl.createImageFromGroup</code></li>
<li><code>scrawl.createImageFromEntity</code></li>
</ul>
<p>Assets will also be created when Picture entitys or Pattern styles are defined using a ‘scrawl.make’ function (<code>makePicture</code>, <code>makePattern</code>), or updated with the <code>set</code> function, where the <em>imageSource</em>, <em>videoSource</em> or <em>spriteSource</em> key in the argument object has been set to a valid URL path string.</p>
<p>Be aware that <strong>loading assets takes time!</strong> </p>
<ul>
<li>Performing a single render operation immediately after defining or updating a Picture entity or Pattern style will almost certainly fail to render the expected image/sprite/video in the canvas. </li>
<li>The load functionality is asynchronous (using Promises). </li>
<li>To display the resulting images in the canvas, it needs to be running an animation object (for instance, <strong>scrawl.makeRender</strong>) so that updates appear as soon as they have loaded, as part of the animation’s Display cycle functionality.</li>
</ul>
</div>
</li>
<li id="section-3">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-3">§</a>
</div>
<h4 id="imports">Imports</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">import</span> { mergeOver, pushUnique, λ<span class="hljs-literal">null</span>, Ωempty } <span class="hljs-keyword">from</span> <span class="hljs-string">'../core/utilities.js'</span>;</pre></div></div>
</li>
<li id="section-4">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-4">§</a>
</div>
<h4 id="export-function">Export function</h4>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-keyword">function</span> (<span class="hljs-params">P = Ωempty</span>) {</pre></div></div>
</li>
<li id="section-5">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-5">§</a>
</div>
<h4 id="shared-attributes">Shared attributes</h4>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> defaultAttributes = {</pre></div></div>
</li>
<li id="section-6">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-6">§</a>
</div>
<p><strong>sourceLoaded</strong> - A flag to indicate that the source image or video has completed sufficient loading (or streaming) to be usefully consumed by Picture entitys and Pattern styles.</p>
<ul>
<li><strong>Note that this flag cannot be directly or indirectly set.</strong> The asset wrapper’s functionality will handle the checking of load progress, and notify its subscribers that the load has completed as-and-when required.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">sourceLoaded</span>: <span class="hljs-literal">false</span>,</pre></div></div>
</li>
<li id="section-7">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-7">§</a>
</div>
<p><strong>source</strong> - A handle to the DOM element supplying the image - either an <img>, <video> or <canvas> element.</p>
<ul>
<li>Note that the <em><strong>Web Canvas API does not support</strong></em> using the <picture> element as a legitimate image source. </li>
<li>However most browsers allow the <img> element to use <strong>srcset</strong> and <strong>sizes</strong> attributes, which will give them the same type of functionality as picture elements - for example to determine the most appropriately sized image file for the browser/device’s viewport dimensions.</li>
<li>Asset wrappers will detect, and handle actions required, if/when a browser decides to download a new image file, to update the <img> element with a more detailed image, for instance when the browser viewport changes its dimensions, or a device is rotated from portrait to landscape viewing.</li>
<li>The web Canvas API claims that <strong>SVG</strong> images can be used as legitimate image sources for the canvas element. To make this happen, the SVG file needs to be set as the src attribute of an <img> element, and the resulting image will be entirely static, and rasterized! </li>
<li>For this reason, we don’t recommend trying to use SVG files for canvas image sources; instead, the SVG can be included in a Scrawl-canvas display by adding it - as an <svg> element - to a Scrawl-canvas stack (see Demo DOM-003 for an example of this approach).</li>
<li><img> elements using an animated GIF as their src are not supported.</li>
<li><em><strong>Be aware that this attribute cannot be directly or indirectly set.</strong></em> Scrawl-canvas will update it as part of its asset loading and wrapper creation functionality.</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">source</span>: <span class="hljs-literal">null</span>,</pre></div></div>
</li>
<li id="section-8">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-8">§</a>
</div>
<p><strong>subscribers</strong> - An Array containing the Picture entity and Pattern style Objects, who wish to use the asset as their source. </p>
<ul>
<li>Pictures and Patterns may subscribe to a maximum of ONE asset at any given time, though they may set/update that asset subscription to a different asset whenever required (which involves unsubscribing their existing asset).</li>
<li><em><strong>Note that the contents of this Array cannot be directly or indirectly set.</strong></em> Picture entitys and Pattern styles will subscribe and unsubscribe to an asset as part of their source acquisition functionality (via the asset wrapper’s <strong>subscribe</strong> and <strong>unsubscribe</strong> functions).</li>
</ul>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-attr">subscribers</span>: <span class="hljs-literal">null</span>,
};
P.<span class="hljs-property">defs</span> = <span class="hljs-title function_">mergeOver</span>(P.<span class="hljs-property">defs</span>, defaultAttributes);</pre></div></div>
</li>
<li id="section-9">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-9">§</a>
</div>
<h4 id="packet-management">Packet management</h4>
<p>Assets do not include their source images (or videos!) in their packet output. They do include the String name values of each of their subscribers.</p>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">packetExclusions</span> = <span class="hljs-title function_">pushUnique</span>(P.<span class="hljs-property">packetExclusions</span>, [<span class="hljs-string">'sourceLoaded'</span>, <span class="hljs-string">'source'</span>, <span class="hljs-string">'subscribers'</span>]);
P.<span class="hljs-property">finalizePacketOut</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">copy, items</span>) {
<span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span> && <span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span>.<span class="hljs-property">length</span>) {
copy.<span class="hljs-property">subscribers</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span>.<span class="hljs-title function_">map</span>(<span class="hljs-function"><span class="hljs-params">sub</span> =></span> sub.<span class="hljs-property">name</span>);
}
<span class="hljs-keyword">return</span> copy;
};</pre></div></div>
</li>
<li id="section-10">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-10">§</a>
</div>
<h4 id="clone-management">Clone management</h4>
<p>No additional clone functionality defined here</p>
</div>
</li>
<li id="section-11">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-11">§</a>
</div>
<h4 id="kill-management">Kill management</h4>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">kill</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">removeDomEntity = <span class="hljs-literal">false</span></span>) {
<span class="hljs-keyword">if</span> (removeDomEntity && <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>.<span class="hljs-title function_">remove</span>();
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">deregister</span>();
};</pre></div></div>
</li>
<li id="section-12">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-12">§</a>
</div>
<h4 id="get-set-deltaset">Get, Set, deltaSet</h4>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">let</span> G = P.<span class="hljs-property">getters</span>,
S = P.<span class="hljs-property">setters</span>,
D = P.<span class="hljs-property">deltaSetters</span>;</pre></div></div>
</li>
<li id="section-13">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-13">§</a>
</div>
<p><strong>source</strong> - imageAsset.js and videoAsset.js overwrite this function, thus only put here so cell.js also gains the function - which I don’t think it will ever need as cells ARE their own source.</p>
</div>
<div class="content"><div class='highlight'><pre> S.<span class="hljs-property">source</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">item</span>) {
<span class="hljs-keyword">if</span> (item) {</pre></div></div>
</li>
<li id="section-14">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-14">§</a>
</div>
<p>No action required for Canvas objects as they don’t have a source; they ARE the source!</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceLoaded</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">notifySubscribers</span>();
}
};</pre></div></div>
</li>
<li id="section-15">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-15">§</a>
</div>
<p><strong>subscribers</strong> - we disable the ability to set the subscribers Array directly. Picture entitys and Pattern styles will manage their subscription to the asset using their subscribe() and unsubscribe() functions.</p>
</div>
<div class="content"><div class='highlight'><pre> S.<span class="hljs-property">subscribers</span> = λ<span class="hljs-literal">null</span>;</pre></div></div>
</li>
<li id="section-16">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-16">§</a>
</div>
<h4 id="prototype-functions">Prototype functions</h4>
</div>
</li>
<li id="section-17">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-17">§</a>
</div>
<p><code>assetConstructor</code> - Common actions required by <strong>imageAsset</strong>, <strong>spriteAsset</strong>, and <strong>videoAsset</strong> factories as part if their instance constructor work.</p>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">assetConstructor</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">items</span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">makeName</span>(items.<span class="hljs-property">name</span>);
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">register</span>();
<span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span> = [];
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(<span class="hljs-variable language_">this</span>.<span class="hljs-property">defs</span>);
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">set</span>(items);
<span class="hljs-keyword">if</span> (items.<span class="hljs-property">subscribe</span>) <span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span>.<span class="hljs-title function_">push</span>(items.<span class="hljs-property">subscribe</span>);
<span class="hljs-keyword">return</span> <span class="hljs-variable language_">this</span>;
};</pre></div></div>
</li>
<li id="section-18">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-18">§</a>
</div>
<h5 id="subscribe-and-unsubscribe-to-an-asset">Subscribe and unsubscribe to an asset</h5>
<p><code>subscribe</code></p>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">subscribe</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">sub</span>) {
<span class="hljs-keyword">if</span> (sub && sub.<span class="hljs-property">name</span>) {
<span class="hljs-keyword">let</span> name = sub.<span class="hljs-property">name</span>;
<span class="hljs-keyword">if</span> (<span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span>.<span class="hljs-title function_">every</span>(<span class="hljs-function"><span class="hljs-params">item</span> =></span> item.<span class="hljs-property">name</span> !== name)) <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">subscribeAction</span>(sub);
}
};</pre></div></div>
</li>
<li id="section-19">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-19">§</a>
</div>
<p><code>subscribeAction</code> - separated out because cells handle things differently (they ARE the source)</p>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">subscribeAction</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">sub</span>) {
<span class="hljs-keyword">if</span> (sub) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span>.<span class="hljs-title function_">push</span>(sub);
sub.<span class="hljs-property">asset</span> = <span class="hljs-variable language_">this</span>;
sub.<span class="hljs-property">source</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-title function_">notifySubscriber</span>(sub);
}
};</pre></div></div>
</li>
<li id="section-20">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-20">§</a>
</div>
<p><code>unsubscribe</code></p>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">unsubscribe</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">sub</span>) {
<span class="hljs-keyword">if</span> (sub && sub.<span class="hljs-property">name</span>) {
<span class="hljs-keyword">let</span> name = sub.<span class="hljs-property">name</span>,
index = <span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span>.<span class="hljs-title function_">findIndex</span>(<span class="hljs-function"><span class="hljs-params">item</span> =></span> item.<span class="hljs-property">name</span> === name);
<span class="hljs-keyword">if</span> (index >= <span class="hljs-number">0</span>) {
sub.<span class="hljs-property">source</span> = <span class="hljs-literal">null</span>;
sub.<span class="hljs-property">asset</span> = <span class="hljs-literal">null</span>;
sub.<span class="hljs-property">sourceNaturalHeight</span> = <span class="hljs-number">0</span>;
sub.<span class="hljs-property">sourceNaturalWidth</span> = <span class="hljs-number">0</span>;
sub.<span class="hljs-property">sourceLoaded</span> = <span class="hljs-literal">false</span>;
<span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span>.<span class="hljs-title function_">splice</span>(index, <span class="hljs-number">1</span>)
}
}
};</pre></div></div>
</li>
<li id="section-21">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-21">§</a>
</div>
<p><code>notifySubscribers</code>, <code>notifySubscriber</code> - Subscriber notification in the asset factories will happen when something changes with the image. Changes vary across the different types of asset:</p>
<ul>
<li><strong>imageAsset</strong> - needs to update its subscribers when an image completes loading - or, for <img> sources with srcset (and sizes) attributes, when the image completes a reload of its source data.</li>
<li><strong>spriteAsset</strong> - will also update its subscribers each time it moves to a new sprite image frame, if the sprite is being animated</li>
<li><strong>videoAsset</strong> - will update its subscribers for every RAF tick while the video is playing, or if the video is halted and seeks to a different time in the video play stream.</li>
<li><strong>noiseAsset</strong> - will update its subscribers when any of its attributes changes (Note: factory/noiseAsset.js overwrites these functions).</li>
<li><strong>reactionDiffusionAsset</strong> - will update its subscribers when any of its attributes changes (Note: factory/reactionDiffusionAsset.js overwrites these functions).</li>
</ul>
<p>All notifications are push; the notification is achieved by setting various attributes and flags in each subscriber.</p>
</div>
<div class="content"><div class='highlight'><pre> P.<span class="hljs-property">notifySubscribers</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) {
<span class="hljs-variable language_">this</span>.<span class="hljs-property">subscribers</span>.<span class="hljs-title function_">forEach</span>(<span class="hljs-function"><span class="hljs-params">sub</span> =></span> <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">notifySubscriber</span>(sub), <span class="hljs-variable language_">this</span>);
};
P.<span class="hljs-property">notifySubscriber</span> = <span class="hljs-keyword">function</span> (<span class="hljs-params">sub</span>) {
sub.<span class="hljs-property">sourceNaturalWidth</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalWidth</span>;
sub.<span class="hljs-property">sourceNaturalHeight</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceNaturalHeight</span>;
sub.<span class="hljs-property">sourceLoaded</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">sourceLoaded</span>;
sub.<span class="hljs-property">source</span> = <span class="hljs-variable language_">this</span>.<span class="hljs-property">source</span>;
sub.<span class="hljs-property">dirtyImage</span> = <span class="hljs-literal">true</span>;
sub.<span class="hljs-property">dirtyCopyStart</span> = <span class="hljs-literal">true</span>;
sub.<span class="hljs-property">dirtyCopyDimensions</span> = <span class="hljs-literal">true</span>;
sub.<span class="hljs-property">dirtyImageSubscribers</span> = <span class="hljs-literal">true</span>;
sub.<span class="hljs-property">dirtyFilterIdentifier</span> = <span class="hljs-literal">true</span>;
};</pre></div></div>
</li>
<li id="section-22">
<div class="annotation">
<div class="sswrap ">
<a class="ss" href="#section-22">§</a>
</div>
<p>Return the prototype</p>
</div>
<div class="content"><div class='highlight'><pre> <span class="hljs-keyword">return</span> P;
};</pre></div></div>
</li>
</ul>
</div>
</body>
</html>