UNPKG

gs-events

Version:

事件分发器(同步)

212 lines (191 loc) 12 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <base data-ice="baseUrl" href="../../"> <title data-ice="title">src/EventListenerOptions.js | gs-events</title> <link type="text/css" rel="stylesheet" href="css/style.css"> <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> <script src="script/prettify/prettify.js"></script> <script src="script/manual.js"></script> <meta name="description" content="&#x4E8B;&#x4EF6;&#x5206;&#x53D1;&#x5668;&#xFF08;&#x540C;&#x6B65;&#xFF09;"><meta property="twitter:card" content="summary"><meta property="twitter:title" content="gs-events"><meta property="twitter:description" content="&#x4E8B;&#x4EF6;&#x5206;&#x53D1;&#x5668;&#xFF08;&#x540C;&#x6B65;&#xFF09;"></head> <body class="layout-container" data-ice="rootContainer"> <header> <a href="./">Home</a> <a href="identifiers.html">Reference</a> <a href="source.html">Source</a> <div class="search-box"> <span> <img src="./image/search.png"> <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> </span> <ul class="search-result"></ul> </div> <a style="position:relative; top:3px;" href="https://github.com/guless/events"><img width="20px" src="./image/github.png"></a></header> <nav class="navigation" data-ice="nav"><div> <ul> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/CustomEvent.js~CustomEvent.html">CustomEvent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/Event.js~Event.html">Event</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/EventDispatcher.js~EventDispatcher.html">EventDispatcher</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/EventListener.js~EventListener.html">EventListener</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/EventListenerOptions.js~EventListenerOptions.html">EventListenerOptions</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/EventPhase.js~EventPhase.html">EventPhase</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-interface">I</span><span data-ice="name"><span><a href="class/src/IEventDispatcher.js~IEventDispatcher.html">IEventDispatcher</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-interface">I</span><span data-ice="name"><span><a href="class/src/IEventListener.js~IEventListener.html">IEventListener</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-interface">I</span><span data-ice="name"><span><a href="class/src/IEventListenerOptions.js~IEventListenerOptions.html">IEventListenerOptions</a></span></span></li> </ul> </div> </nav> <div class="content" data-ice="content"><h1 data-ice="title">src/EventListenerOptions.js</h1> <pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// @Copyright ~2018 &#x261C;Samlv9&#x261E; and other contributors /// @MIT-LICENSE | 1.0.0 | https://api.guless.com/ /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// }| /// }| /// }| &#x3000; &#x3078;&#x3000;&#x3000;&#x3000; &#xFF0F;| /// _______ _______ ______ }| /&#x3000;&#x2502;&#x3000;&#x3000; &#xFF0F; &#xFF0F; /// / ___ | |_ __ \ .&apos; ____ &apos;. }| &#x2502;&#x3000;Z &#xFF3F;,&#xFF1C;&#x3000;&#xFF0F;&#x3000;&#x3000; /`&#x30FD; /// | (__ \_| | |__) | | (____) | }| &#x2502;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x30FD;&#x3000;&#x3000; /&#x3000;&#x3000;&#x3009; /// &apos;.___`-. | __ / &apos;_.____. | }| Y&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;`&#x3000; /&#x3000;&#x3000;/ /// |`\____) | _| | \ \_ | \____| | }| &#xFF72;&#x25CF;&#x3000;&#xFF64;&#x3000;&#x25CF;&#x3000;&#x3000;&#x2282;&#x2283;&#x3008;&#x3000;&#x3000;/ /// |_______.&apos; |____| |___| \______,&apos; }| ()&#x3000; v&#x3000;&#x3000;&#x3000;&#x3000;|&#x3000;&#xFF3C;&#x3008; /// |=========================================\| &#x3000;&gt;&#xFF70; &#xFF64;_&#x3000; &#x30A3;&#x3000; &#x2502; &#xFF0F;&#xFF0F; /// |&gt; LESS IS MORE || / &#x3078;&#x3000;&#x3000; /&#x3000;&#xFF89;&#xFF1C;|&#xFF3C;&#xFF3C; /// `=========================================/| &#x30FD;_&#xFF89;&#x3000;&#x3000;(_&#xFF0F;&#x3000; &#x2502;&#xFF0F;&#xFF0F; /// }| 7&#x3000;&#x3000;&#x3000;&#x3000;&#x3000;&#x3000; |&#xFF0F; /// }| &#xFF1E;&#x2015;r&#xFFE3;&#xFFE3;`&#xFF70;&#x2015;&#xFF3F;` /// }| /// }| /// Permission is hereby granted, free of charge, to any person obtaining a copy /// of this software and associated documentation files (the &quot;Software&quot;), to deal /// in the Software without restriction, including without limitation the rights /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell /// copies of the Software, and to permit persons to whom the Software is /// furnished to do so, subject to the following conditions: /// /// The above copyright notice and this permission notice shall be included in all /// copies or substantial portions of the Software. /// /// THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN /// THE SOFTWARE. import IEventDispatcher from &quot;./IEventDispatcher&quot;; import IEventListenerOptions from &quot;./IEventListenerOptions&quot;; /** * &#x5B9A;&#x4E49;&#x4FA6;&#x542C;&#x5668;&#x914D;&#x7F6E;&#x9009;&#x9879;&#x3002; * @implements {IEventListenerOptions} * @see {@link EventListener} * @see {@link EventDispatcher} * @since 1.0.0 */ export default class EventListenerOptions /*&lt; implements IEventListenerOptions &gt;*/ { /** * &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x4FA6;&#x542C;&#x5668;&#x9009;&#x9879;&#x5BF9;&#x8C61;&#x3002; * * @param {IEventDispatcher} [scope=null] - &#x6307;&#x5B9A;&#x4FA6;&#x542C;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x5BF9;&#x8C61;&#x3002; * @param {Boolean} [once=false] - &#x6307;&#x793A;&#x4FA6;&#x542C;&#x5668;&#x662F;&#x5426;&#x5728;&#x6267;&#x884C;&#x540E;&#xFF0C;&#x81EA;&#x52A8;&#x4ECE;&#x6D3E;&#x53D1;&#x5668;&#x4E2D;&#x79FB;&#x9664;&#x3002; * @param {Boolean} [useCapture=false] - &#x6307;&#x793A;&#x4FA6;&#x542C;&#x5668;&#x662F;&#x5426;&#x5728;&#x6355;&#x83B7;&#x9636;&#x6BB5;&#x5904;&#x7406;&#x4E8B;&#x4EF6;&#x3002; * @param {Number} [priority=0] - &#x6307;&#x793A;&#x4FA6;&#x542C;&#x5668;&#x5728;&#x6D3E;&#x53D1;&#x4E8B;&#x4EF6;&#x65F6;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#xFF08;&#x4E8B;&#x4EF6;&#x6D3E;&#x53D1;&#x65F6;&#x4F1A;&#x4F18;&#x5148;&#x6267;&#x884C;&#x9AD8;&#x4F18;&#x5148;&#x7EA7;&#x7684;&#x4FA6;&#x542C;&#x5668;&#xFF09;&#x3002; * @since 1.0.0 */ constructor( scope = null, once = false, useCapture = false, priority = 0 ) { /** * @type {IEventDispatcher} */ this._scope = scope; /** * @type {Boolean} */ this._once = once; /** * @type {Boolean} */ this._useCapture = useCapture; /** * @type {Number} */ this._priority = priority; } /** * &#x83B7;&#x53D6;&#x4FA6;&#x542C;&#x5668;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x5BF9;&#x8C61;&#x3002; * @type {IEventDispatcher} * @since 1.0.0 */ get scope() { return this._scope; } /** * &#x6307;&#x793A;&#x4FA6;&#x542C;&#x5668;&#x662F;&#x5426;&#x5728;&#x6267;&#x884C;&#x540E;&#xFF0C;&#x81EA;&#x52A8;&#x4ECE;&#x6D3E;&#x53D1;&#x5668;&#x4E2D;&#x79FB;&#x9664;&#x3002; * @type {Boolean} * @since 1.0.0 */ get once() { return this._once; } /** * &#x6307;&#x793A;&#x4FA6;&#x542C;&#x5668;&#x662F;&#x5426;&#x5728;&#x6355;&#x83B7;&#x9636;&#x6BB5;&#x5904;&#x7406;&#x4E8B;&#x4EF6;&#x3002; * @type {Boolean} * @since 1.0.0 */ get useCapture() { return this._useCapture; } /** * &#x6307;&#x793A;&#x4FA6;&#x542C;&#x5668;&#x5728;&#x6D3E;&#x53D1;&#x4E8B;&#x4EF6;&#x65F6;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#x3002; * @type {Number} * @since 1.0.0 */ get priority() { return this._priority; } /** * &#x4F7F;&#x7528;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x53C2;&#x6570;&#xFF0C;&#x521D;&#x59CB;&#x5316;&#x5F53;&#x524D;&#x914D;&#x7F6E;&#x9009;&#x9879;&#x3002; * * - &#x5982;&#x679C; `options` &#x662F;&#x4E00;&#x4E2A; `Boolean` &#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF0C;&#x5219;&#x5C06; `options` &#x89C6;&#x4E3A; {@link EventListenerOptions#useCapture}&#x3002; * - &#x5982;&#x679C; `options` &#x662F;&#x4E00;&#x4E2A; `IEventListenerOptions` &#x7C7B;&#x578B;&#x7684;&#x503C;&#xFF0C;&#x5219;&#x62F7;&#x8D1D; `options` &#x7684;&#x503C;&#x5230;&#x5F53;&#x524D;&#x914D;&#x7F6E;&#x9009;&#x9879;&#x4E2D;&#x3002; * @param {Boolean|IEventListenerOptions} [options=false] - &#x6307;&#x5B9A;&#x4FA6;&#x542C;&#x5668;&#x7684;&#x914D;&#x7F6E;&#x9009;&#x9879;&#x3002; * @example * const dispatcher = new EventDispatcher(); * const options = new EventListenerOptions(); * options.initWithParams({ &quot;once&quot;: true, &quot;scope&quot;: this }); * * dispatcher.addEventListener(&quot;custom&quot;, ( evt ) =&gt; { * /// &#x8BE5;&#x4E8B;&#x4EF6;&#x4FA6;&#x542C;&#x5668;&#x5728;&#x6267;&#x884C;&#x540E;&#xFF0C;&#x4F1A;&#x81EA;&#x52A8;&#x4ECE; `dispatcher` &#x6D3E;&#x53D1;&#x5668;&#x4E2D;&#x79FB;&#x9664;&#x3002; * console.log(&quot;success&quot;); * }, options); * * dispatcher.dispatchEvent(new Event(&quot;custom&quot;, false, false)); * @returns {this} * @since 1.0.0 */ initWithParams( options = false ) { if ( typeof options == &quot;boolean&quot; ) { this._useCapture = options; } else { if ( options.scope !== void 0 ) { this._scope = options.scope; } if ( options.once !== void 0 ) { this._once = options.once; } if ( options.useCapture !== void 0 ) { this._useCapture = options.useCapture; } if ( options.priority !== void 0 ) { this._priority = options.priority; } } return this; } }</code></pre> </div> <footer class="footer"> Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.0.4)</span><img src="./image/esdoc-logo-mini-black.png"></a> </footer> <script src="script/search_index.js"></script> <script src="script/search.js"></script> <script src="script/pretty-print.js"></script> <script src="script/inherited-summary.js"></script> <script src="script/test-summary.js"></script> <script src="script/inner-link.js"></script> <script src="script/patch-for-local.js"></script> </body> </html>