module-barejs.Destroyable.html 20 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Class: Destroyable</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Class: Destroyable</h1>
  17. <section>
  18. <header>
  19. <h2><span class="attribs"><span class="type-signature"></span></span>
  20. <span class="ancestors"><a href="module-barejs.html">barejs</a>.</span>Destroyable<span class="signature">()</span><span class="type-signature"></span></h2>
  21. <div class="class-description"><p>Class that adds lifetime management to JavaScript objects. Destroyable provides a few features to ensure
  22. the JavaScript garbage collector can recollect memory as soon as possible.</p>
  23. <p>A Destroyable instance can own other objects. The ownership in this case implies: if this instance is destroyed,
  24. the instance I own should also be destroyed. Destroyable can own any object having either a destroy or remove method.</p>
  25. <p>A Destroyable instance can also ref other objects. The reference is automatically cleared on destroy. If the ref-ed
  26. object is a Destroyable, the reference is also cleared if the target gets destroyed.</p>
  27. <p>Owned objects are also destroyed if this Destroyable is destroyed.
  28. Referenced objects are automatically unlinked if this object is destroyed, and even if the referenced
  29. is destroyed (in case the referenced object is Destroyable).</p></div>
  30. </header>
  31. <article>
  32. <div class="container-overview">
  33. <h2>Constructor</h2>
  34. <h4 class="name" id="Destroyable"><span class="type-signature"></span>new Destroyable<span class="signature">()</span><span class="type-signature"></span></h4>
  35. <dl class="details">
  36. <dt class="tag-source">Source:</dt>
  37. <dd class="tag-source"><ul class="dummy"><li>
  38. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line205">line 205</a>
  39. </li></ul></dd>
  40. </dl>
  41. </div>
  42. <h3 class="subsection-title">Methods</h3>
  43. <h4 class="name" id=".isDestroyed"><span class="type-signature">(static) </span>isDestroyed<span class="signature">(_target)</span><span class="type-signature"> &rarr; {boolean}</span></h4>
  44. <div class="description">
  45. <p>Check if _target is destroyed.</p>
  46. </div>
  47. <h5>Parameters:</h5>
  48. <table class="params">
  49. <thead>
  50. <tr>
  51. <th>Name</th>
  52. <th>Type</th>
  53. <th class="last">Description</th>
  54. </tr>
  55. </thead>
  56. <tbody>
  57. <tr>
  58. <td class="name"><code>_target</code></td>
  59. <td class="type">
  60. <span class="param-type">module:barejs.Destroyable~Destroyable</span>
  61. </td>
  62. <td class="description last"><p>The destroyable to check</p></td>
  63. </tr>
  64. </tbody>
  65. </table>
  66. <dl class="details">
  67. <dt class="tag-source">Source:</dt>
  68. <dd class="tag-source"><ul class="dummy"><li>
  69. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line45">line 45</a>
  70. </li></ul></dd>
  71. </dl>
  72. <h5>Returns:</h5>
  73. <div class="param-desc">
  74. <p>True if the target has been destroyed, false otherwise.</p>
  75. </div>
  76. <dl>
  77. <dt>
  78. Type
  79. </dt>
  80. <dd>
  81. <span class="param-type">boolean</span>
  82. </dd>
  83. </dl>
  84. <h4 class="name" id="addDestroyListener"><span class="type-signature"></span>addDestroyListener<span class="signature">(_listener)</span><span class="type-signature"> &rarr; {function}</span></h4>
  85. <div class="description">
  86. <p>Register a destroy listener for this Destroyable object.</p>
  87. </div>
  88. <h5>Parameters:</h5>
  89. <table class="params">
  90. <thead>
  91. <tr>
  92. <th>Name</th>
  93. <th>Type</th>
  94. <th class="last">Description</th>
  95. </tr>
  96. </thead>
  97. <tbody>
  98. <tr>
  99. <td class="name"><code>_listener</code></td>
  100. <td class="type">
  101. <span class="param-type"><a href="module-barejs.Destroyable.html#~DestroyListener">module:barejs.Destroyable~DestroyListener</a></span>
  102. </td>
  103. <td class="description last"><p>The listener function to add.</p></td>
  104. </tr>
  105. </tbody>
  106. </table>
  107. <dl class="details">
  108. <dt class="tag-source">Source:</dt>
  109. <dd class="tag-source"><ul class="dummy"><li>
  110. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line332">line 332</a>
  111. </li></ul></dd>
  112. </dl>
  113. <h5>Returns:</h5>
  114. <div class="param-desc">
  115. <p>the listener</p>
  116. </div>
  117. <dl>
  118. <dt>
  119. Type
  120. </dt>
  121. <dd>
  122. <span class="param-type">function</span>
  123. </dd>
  124. </dl>
  125. <h4 class="name" id="destroy"><span class="type-signature"></span>destroy<span class="signature">()</span><span class="type-signature"></span></h4>
  126. <div class="description">
  127. <p>Destroy method that will notify registered listeners and clean up references.</p>
  128. </div>
  129. <dl class="details">
  130. <dt class="tag-source">Source:</dt>
  131. <dd class="tag-source"><ul class="dummy"><li>
  132. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line282">line 282</a>
  133. </li></ul></dd>
  134. </dl>
  135. <h4 class="name" id="destroyAll"><span class="type-signature"></span>destroyAll<span class="signature">(_collection)</span><span class="type-signature"></span></h4>
  136. <div class="description">
  137. <p>Utility method that will iterate a collection and destroy all items in it.</p>
  138. </div>
  139. <h5>Parameters:</h5>
  140. <table class="params">
  141. <thead>
  142. <tr>
  143. <th>Name</th>
  144. <th>Type</th>
  145. <th class="last">Description</th>
  146. </tr>
  147. </thead>
  148. <tbody>
  149. <tr>
  150. <td class="name"><code>_collection</code></td>
  151. <td class="type">
  152. <span class="param-type">object</span>
  153. </td>
  154. <td class="description last"><p>An object with a forEach method or length property (e.g. an Array).</p></td>
  155. </tr>
  156. </tbody>
  157. </table>
  158. <dl class="details">
  159. <dt class="tag-source">Source:</dt>
  160. <dd class="tag-source"><ul class="dummy"><li>
  161. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line496">line 496</a>
  162. </li></ul></dd>
  163. </dl>
  164. <h4 class="name" id="own"><span class="type-signature"></span>own<span class="signature">()</span><span class="type-signature"> &rarr; {Array}</span></h4>
  165. <div class="description">
  166. <p>Own a number of handles. Returns an array of the owned handles.</p>
  167. </div>
  168. <dl class="details">
  169. <dt class="tag-source">Source:</dt>
  170. <dd class="tag-source"><ul class="dummy"><li>
  171. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line362">line 362</a>
  172. </li></ul></dd>
  173. </dl>
  174. <h5>Returns:</h5>
  175. <div class="param-desc">
  176. <p>The owned handles.</p>
  177. </div>
  178. <dl>
  179. <dt>
  180. Type
  181. </dt>
  182. <dd>
  183. <span class="param-type">Array</span>
  184. </dd>
  185. </dl>
  186. <h4 class="name" id="ownMember"><span class="type-signature"></span>ownMember<span class="signature">(_name, _target)</span><span class="type-signature"></span></h4>
  187. <div class="description">
  188. <p>The ownMember function combines ref and own into 1 call. The target is owned and then ref-ed as _name.</p>
  189. </div>
  190. <h5>Parameters:</h5>
  191. <table class="params">
  192. <thead>
  193. <tr>
  194. <th>Name</th>
  195. <th>Type</th>
  196. <th class="last">Description</th>
  197. </tr>
  198. </thead>
  199. <tbody>
  200. <tr>
  201. <td class="name"><code>_name</code></td>
  202. <td class="type">
  203. <span class="param-type">string</span>
  204. </td>
  205. <td class="description last"><p>The name of the member.</p></td>
  206. </tr>
  207. <tr>
  208. <td class="name"><code>_target</code></td>
  209. <td class="type">
  210. <span class="param-type"><a href="module-barejs.Destroyable.html">module:barejs.Destroyable</a></span>
  211. </td>
  212. <td class="description last"><p>The target to own.</p></td>
  213. </tr>
  214. </tbody>
  215. </table>
  216. <dl class="details">
  217. <dt class="tag-source">Source:</dt>
  218. <dd class="tag-source"><ul class="dummy"><li>
  219. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line481">line 481</a>
  220. </li></ul></dd>
  221. </dl>
  222. <h5>Returns:</h5>
  223. <div class="param-desc">
  224. <p>The owned _target</p>
  225. </div>
  226. <h4 class="name" id="ref"><span class="type-signature"></span>ref<span class="signature">(_name, _target)</span><span class="type-signature"></span></h4>
  227. <div class="description">
  228. <p>Reference a target as a member property that will be unlinked on destroy.
  229. If the referenced target is also Destroyable, the ref is also cleared if the target is destroyed.</p>
  230. </div>
  231. <h5>Parameters:</h5>
  232. <table class="params">
  233. <thead>
  234. <tr>
  235. <th>Name</th>
  236. <th>Type</th>
  237. <th class="last">Description</th>
  238. </tr>
  239. </thead>
  240. <tbody>
  241. <tr>
  242. <td class="name"><code>_name</code></td>
  243. <td class="type">
  244. <span class="param-type">string</span>
  245. </td>
  246. <td class="description last"><p>The name to reference.</p></td>
  247. </tr>
  248. <tr>
  249. <td class="name"><code>_target</code></td>
  250. <td class="type">
  251. <span class="param-type">object</span>
  252. </td>
  253. <td class="description last"><p>The object to assign to the reference.</p></td>
  254. </tr>
  255. </tbody>
  256. </table>
  257. <dl class="details">
  258. <dt class="tag-source">Source:</dt>
  259. <dd class="tag-source"><ul class="dummy"><li>
  260. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line378">line 378</a>
  261. </li></ul></dd>
  262. </dl>
  263. <h5>Returns:</h5>
  264. <div class="param-desc">
  265. <p>The value of this[_name].</p>
  266. </div>
  267. <h4 class="name" id="removeDestroyListener"><span class="type-signature"></span>removeDestroyListener<span class="signature">(_listener)</span><span class="type-signature"></span></h4>
  268. <div class="description">
  269. <p>Unregister a destroy listener for this Destroyable object.</p>
  270. </div>
  271. <h5>Parameters:</h5>
  272. <table class="params">
  273. <thead>
  274. <tr>
  275. <th>Name</th>
  276. <th>Type</th>
  277. <th class="last">Description</th>
  278. </tr>
  279. </thead>
  280. <tbody>
  281. <tr>
  282. <td class="name"><code>_listener</code></td>
  283. <td class="type">
  284. <span class="param-type"><a href="module-barejs.Destroyable.html#~DestroyListener">module:barejs.Destroyable~DestroyListener</a></span>
  285. </td>
  286. <td class="description last"><p>The listener function to remove.</p></td>
  287. </tr>
  288. </tbody>
  289. </table>
  290. <dl class="details">
  291. <dt class="tag-source">Source:</dt>
  292. <dd class="tag-source"><ul class="dummy"><li>
  293. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line348">line 348</a>
  294. </li></ul></dd>
  295. </dl>
  296. <h4 class="name" id="unref"><span class="type-signature"></span>unref<span class="signature">(_name, _value<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
  297. <div class="description">
  298. <p>Remove a reference (by name). If the name was given to ownMember, the member is NOT
  299. removed from the list of owned targets.
  300. Does NOT destroy the value currently referenced.</p>
  301. </div>
  302. <h5>Parameters:</h5>
  303. <table class="params">
  304. <thead>
  305. <tr>
  306. <th>Name</th>
  307. <th>Type</th>
  308. <th>Attributes</th>
  309. <th class="last">Description</th>
  310. </tr>
  311. </thead>
  312. <tbody>
  313. <tr>
  314. <td class="name"><code>_name</code></td>
  315. <td class="type">
  316. <span class="param-type">string</span>
  317. </td>
  318. <td class="attributes">
  319. </td>
  320. <td class="description last"><p>the name to remove the reference to</p></td>
  321. </tr>
  322. <tr>
  323. <td class="name"><code>_value</code></td>
  324. <td class="type">
  325. <span class="param-type">object</span>
  326. |
  327. <span class="param-type">function</span>
  328. </td>
  329. <td class="attributes">
  330. &lt;optional><br>
  331. </td>
  332. <td class="description last"><p>If a value is provided (and is not null), unref will only clear the reference if _value equals whatever is currently ref-ed.</p></td>
  333. </tr>
  334. </tbody>
  335. </table>
  336. <dl class="details">
  337. <dt class="tag-source">Source:</dt>
  338. <dd class="tag-source"><ul class="dummy"><li>
  339. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line444">line 444</a>
  340. </li></ul></dd>
  341. </dl>
  342. <h3 class="subsection-title">Type Definitions</h3>
  343. <h4 class="name" id="~DestroyListener"><span class="type-signature"></span>DestroyListener<span class="signature">(_destroyed)</span><span class="type-signature"></span></h4>
  344. <div class="description">
  345. <p>Destroy listeners are called with one argument; the Destroyed object.</p>
  346. </div>
  347. <h5>Parameters:</h5>
  348. <table class="params">
  349. <thead>
  350. <tr>
  351. <th>Name</th>
  352. <th>Type</th>
  353. <th class="last">Description</th>
  354. </tr>
  355. </thead>
  356. <tbody>
  357. <tr>
  358. <td class="name"><code>_destroyed</code></td>
  359. <td class="type">
  360. <span class="param-type"><a href="module-barejs.Destroyable.html">module:barejs.Destroyable</a></span>
  361. </td>
  362. <td class="description last"><p>The Destroyable that got destroyed.</p></td>
  363. </tr>
  364. </tbody>
  365. </table>
  366. <dl class="details">
  367. <dt class="tag-source">Source:</dt>
  368. <dd class="tag-source"><ul class="dummy"><li>
  369. <a href="Destroyable.js.html">Destroyable.js</a>, <a href="Destroyable.js.html#line512">line 512</a>
  370. </li></ul></dd>
  371. </dl>
  372. </article>
  373. </section>
  374. </div>
  375. <nav>
  376. <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-barejs.html">barejs</a></li><li><a href="module-barejs_polyfill.html">barejs/polyfill</a></li><li><a href="module-barejs_polyfill_Intl.html">barejs/polyfill/Intl</a></li></ul><h3>Classes</h3><ul><li><a href="module-barejs.decl.html">decl</a></li><li><a href="module-barejs.decl-Enum.html">Enum</a></li><li><a href="module-barejs.decl-Interface.html">Interface</a></li><li><a href="module-barejs.decl-SpecialType.html">SpecialType</a></li><li><a href="module-barejs.Destroyable.html">Destroyable</a></li><li><a href="module-barejs.EventArgs.html">EventArgs</a></li><li><a href="module-barejs.Evented.html">Evented</a></li><li><a href="module-barejs.Evented-EventedHandle.html">EventedHandle</a></li><li><a href="module-barejs.Exception.html">Exception</a></li><li><a href="module-barejs_polyfill.Array.html">Array</a></li><li><a href="module-barejs_polyfill.Date.html">Date</a></li><li><a href="module-barejs_polyfill.EntryStore.html">EntryStore</a></li><li><a href="module-barejs_polyfill.EntryStore.Iterator.html">Iterator</a></li><li><a href="module-barejs_polyfill.Function.html">Function</a></li><li><a href="module-barejs_polyfill.Map.html">Map</a></li><li><a href="module-barejs_polyfill.Map-MapIterator.html">MapIterator</a></li><li><a href="module-barejs_polyfill.Math.html">Math</a></li><li><a href="module-barejs_polyfill.Number.html">Number</a></li><li><a href="module-barejs_polyfill.Object.html">Object</a></li><li><a href="module-barejs_polyfill.Promise.html">Promise</a></li><li><a href="module-barejs_polyfill.Set.html">Set</a></li><li><a href="module-barejs_polyfill.Set-SetIterator.html">SetIterator</a></li><li><a href="module-barejs_polyfill.String.html">String</a></li><li><a href="module-barejs_polyfill.Symbol.html">Symbol</a></li><li><a href="module-barejs_polyfill.WeakMap.html">WeakMap</a></li><li><a href="module-barejs_polyfill.WeakSet.html">WeakSet</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat.html">DateTimeFormat</a></li><li><a href="module-barejs_polyfill_Intl.DateTimeFormat-DateTimeFormatOptions.html">DateTimeFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat.html">NumberFormat</a></li><li><a href="module-barejs_polyfill_Intl.NumberFormat-NumberFormatOptions.html">NumberFormatOptions</a></li><li><a href="module-barejs_polyfill_Intl-Format.html">Format</a></li></ul>
  377. </nav>
  378. <br class="clear">
  379. <footer>
  380. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Oct 03 2018 15:59:34 GMT+0200 (W. Europe Daylight Time)
  381. </footer>
  382. <script> prettyPrint(); </script>
  383. <script src="scripts/linenumber.js"> </script>
  384. </body>
  385. </html>