Best JavaScript code snippet using wpt
test_Signal.js
Source:test_Signal.js
...128 bObject.bMethod = function() {129 i++;130 };131 ident = connect(hasSignals, 'signalOne', aFunction);132 signal(hasSignals, 'signalOne');133 t.is(i, 2, 'Connecting function');134 i = 0;135 disconnect(ident);136 signal(hasSignals, 'signalOne');137 t.is(i, 0, 'New style disconnecting function');138 i = 0;139 ident = connect(hasSignals, 'signalOne', bFunction);140 signal(hasSignals, 'signalOne', 1, 2);141 t.is(i, 3, 'Connecting function');142 i = 0;143 disconnect(ident);144 signal(hasSignals, 'signalOne', 1, 2);145 t.is(i, 0, 'New style disconnecting function');146 i = 0;147 connect(hasSignals, 'signalOne', aFunction);148 signal(hasSignals, 'signalOne');149 t.is(i, 2, 'Connecting function');150 i = 0;151 disconnect(hasSignals, 'signalOne', aFunction);152 signal(hasSignals, 'signalOne');153 t.is(i, 0, 'Old style disconnecting function');154 i = 0;155 ident = connect(hasSignals, 'signalOne', aObject, aObject.aMethod);156 signal(hasSignals, 'signalOne');157 t.is(i, 1, 'Connecting obj-function');158 i = 0;159 disconnect(ident);160 signal(hasSignals, 'signalOne');161 t.is(i, 0, 'New style disconnecting obj-function');162 i = 0;163 connect(hasSignals, 'signalOne', aObject, aObject.aMethod);164 signal(hasSignals, 'signalOne');165 t.is(i, 1, 'Connecting obj-function');166 i = 0;167 disconnect(hasSignals, 'signalOne', aObject, aObject.aMethod);168 signal(hasSignals, 'signalOne');169 t.is(i, 0, 'Disconnecting obj-function');170 i = 0;171 ident = connect(hasSignals, 'signalTwo', aObject, 'aMethod');172 signal(hasSignals, 'signalTwo');173 t.is(i, 1, 'Connecting obj-string');174 i = 0;175 disconnect(ident);176 signal(hasSignals, 'signalTwo');177 t.is(i, 0, 'New style disconnecting obj-string');178 i = 0;179 connect(hasSignals, 'signalTwo', aObject, 'aMethod');180 signal(hasSignals, 'signalTwo');181 t.is(i, 1, 'Connecting obj-string');182 i = 0;183 disconnect(hasSignals, 'signalTwo', aObject, 'aMethod');184 signal(hasSignals, 'signalTwo');185 t.is(i, 0, 'Old style disconnecting obj-string');186 i = 0;187 var shouldRaise = function() { return undefined.attr; };188 try {189 connect(hasSignals, 'signalOne', shouldRaise);190 signal(hasSignals, 'signalOne');191 t.ok(false, 'An exception was not raised');192 } catch (e) {193 t.ok(true, 'An exception was raised');194 }195 disconnect(hasSignals, 'signalOne', shouldRaise);196 t.is(i, 0, 'Exception raised, signal should not have fired');197 i = 0;198 199 connect(hasSignals, 'signalOne', aObject, 'aMethod');200 connect(hasSignals, 'signalOne', aObject, 'bMethod');201 signal(hasSignals, 'signalOne');202 t.is(i, 2, 'Connecting one signal to two slots in one object');203 i = 0;204 205 disconnect(hasSignals, 'signalOne', aObject, 'aMethod');206 disconnect(hasSignals, 'signalOne', aObject, 'bMethod');207 signal(hasSignals, 'signalOne');208 t.is(i, 0, 'Disconnecting one signal from two slots in one object');209 i = 0;210 connect(hasSignals, 'signalOne', aObject, 'aMethod');211 connect(hasSignals, 'signalOne', bObject, 'bMethod');212 signal(hasSignals, 'signalOne');213 t.is(i, 2, 'Connecting one signal to two slots in two objects');214 i = 0;215 disconnect(hasSignals, 'signalOne', aObject, 'aMethod');216 disconnect(hasSignals, 'signalOne', bObject, 'bMethod');217 signal(hasSignals, 'signalOne');218 t.is(i, 0, 'Disconnecting one signal from two slots in two objects');219 i = 0;220 221 try {222 connect(nothing, 'signalOne', aObject, 'aMethod');223 signal(nothing, 'signalOne');224 t.ok(false, 'An exception was not raised when connecting undefined');225 } catch (e) {226 t.ok(true, 'An exception was raised when connecting undefined');227 }228 try {229 disconnect(nothing, 'signalOne', aObject, 'aMethod');230 t.ok(false, 'An exception was not raised when disconnecting undefined');231 } catch (e) {232 t.ok(true, 'An exception was raised when disconnecting undefined');233 }234 235 236 try {237 connect(hasSignals, 'signalOne', nothing);238 signal(hasSignals, 'signalOne');239 t.ok(false, 'An exception was not raised when connecting an undefined function');240 } catch (e) {241 t.ok(true, 'An exception was raised when connecting an undefined function');242 }243 try {244 disconnect(hasSignals, 'signalOne', nothing);245 t.ok(false, 'An exception was not raised when disconnecting an undefined function');246 } catch (e) {247 t.ok(true, 'An exception was raised when disconnecting an undefined function');248 }249 250 251 try {252 connect(hasSignals, 'signalOne', aObject, aObject.nothing);253 signal(hasSignals, 'signalOne');254 t.ok(false, 'An exception was not raised when connecting an undefined method');255 } catch (e) {256 t.ok(true, 'An exception was raised when connecting an undefined method');257 }258 259 try {260 connect(hasSignals, 'signalOne', aObject, 'nothing');261 signal(hasSignals, 'signalOne');262 t.ok(false, 'An exception was not raised when connecting an undefined method (as string)');263 } catch (e) {264 t.ok(true, 'An exception was raised when connecting an undefined method (as string)');265 }266 t.is(i, 0, 'Signals should not have fired');267 connect(hasSignals, 'signalOne', aFunction);268 connect(hasSignals, 'signalOne', aObject, 'aMethod');269 disconnectAll(hasSignals, 'signalOne');270 signal(hasSignals, 'signalOne');271 t.is(i, 0, 'disconnectAll works with single explicit signal');272 i = 0;273 connect(hasSignals, 'signalOne', aFunction);274 connect(hasSignals, 'signalOne', aObject, 'aMethod');275 connect(hasSignals, 'signalTwo', aFunction);276 connect(hasSignals, 'signalTwo', aObject, 'aMethod');277 disconnectAll(hasSignals, 'signalOne');278 signal(hasSignals, 'signalOne');279 t.is(i, 0, 'disconnectAll works with single explicit signal');280 signal(hasSignals, 'signalTwo');281 t.is(i, 3, 'disconnectAll does not disconnect unrelated signals');282 i = 0;283 connect(hasSignals, 'signalOne', aFunction);284 connect(hasSignals, 'signalOne', aObject, 'aMethod');285 connect(hasSignals, 'signalTwo', aFunction);286 connect(hasSignals, 'signalTwo', aObject, 'aMethod');287 disconnectAll(hasSignals, 'signalOne', 'signalTwo');288 signal(hasSignals, 'signalOne');289 signal(hasSignals, 'signalTwo');290 t.is(i, 0, 'disconnectAll works with two explicit signals');291 i = 0;292 connect(hasSignals, 'signalOne', aFunction);293 connect(hasSignals, 'signalOne', aObject, 'aMethod');294 connect(hasSignals, 'signalTwo', aFunction);295 connect(hasSignals, 'signalTwo', aObject, 'aMethod');296 disconnectAll(hasSignals, ['signalOne', 'signalTwo']);297 signal(hasSignals, 'signalOne');298 signal(hasSignals, 'signalTwo');299 t.is(i, 0, 'disconnectAll works with two explicit signals as a list');300 i = 0;301 connect(hasSignals, 'signalOne', aFunction);302 connect(hasSignals, 'signalOne', aObject, 'aMethod');303 connect(hasSignals, 'signalTwo', aFunction);304 connect(hasSignals, 'signalTwo', aObject, 'aMethod');305 disconnectAll(hasSignals);306 signal(hasSignals, 'signalOne');307 signal(hasSignals, 'signalTwo');308 t.is(i, 0, 'disconnectAll works with implicit signals');309 i = 0;310 311 var toggle = function() {312 disconnectAll(hasSignals, 'signalOne');313 connect(hasSignals, 'signalOne', aFunction);314 i++;315 };316 317 connect(hasSignals, 'signalOne', aFunction);318 connect(hasSignals, 'signalTwo', function() { i++; });319 connect(hasSignals, 'signalTwo', toggle);320 connect(hasSignals, 'signalTwo', function() { i++; }); // #147321 connect(hasSignals, 'signalTwo', function() { i++; });322 signal(hasSignals, 'signalTwo');323 t.is(i, 4, 'disconnectAll fired in a signal loop works');324 i = 0;325 disconnectAll('signalOne');326 disconnectAll('signalTwo');327 var testfunc = function () { arguments.callee.count++; };328 testfunc.count = 0;329 var testObj = {330 methOne: function () { this.countOne++; }, countOne: 0,331 methTwo: function () { this.countTwo++; }, countTwo: 0332 };333 connect(hasSignals, 'signalOne', testfunc);334 connect(hasSignals, 'signalTwo', testfunc);335 signal(hasSignals, 'signalOne');336 signal(hasSignals, 'signalTwo');337 t.is(testfunc.count, 2, 'disconnectAllTo func precondition');338 disconnectAllTo(testfunc);339 signal(hasSignals, 'signalOne');340 signal(hasSignals, 'signalTwo');341 t.is(testfunc.count, 2, 'disconnectAllTo func');342 connect(hasSignals, 'signalOne', testObj, 'methOne');343 connect(hasSignals, 'signalTwo', testObj, 'methTwo');344 signal(hasSignals, 'signalOne');345 signal(hasSignals, 'signalTwo');346 t.is(testObj.countOne, 1, 'disconnectAllTo obj precondition');347 t.is(testObj.countTwo, 1, 'disconnectAllTo obj precondition');348 disconnectAllTo(testObj);349 signal(hasSignals, 'signalOne');350 signal(hasSignals, 'signalTwo');351 t.is(testObj.countOne, 1, 'disconnectAllTo obj');352 t.is(testObj.countTwo, 1, 'disconnectAllTo obj');353 testObj.countOne = testObj.countTwo = 0;354 connect(hasSignals, 'signalOne', testObj, 'methOne');355 connect(hasSignals, 'signalTwo', testObj, 'methTwo');356 disconnectAllTo(testObj, 'methOne');357 signal(hasSignals, 'signalOne');358 signal(hasSignals, 'signalTwo');359 t.is(testObj.countOne, 0, 'disconnectAllTo obj+str');360 t.is(testObj.countTwo, 1, 'disconnectAllTo obj+str');361 362 has__Connect = {363 count: 0,364 __connect__: function (ident) {365 this.count += arguments.length;366 disconnect(ident);367 }368 };369 connect(has__Connect, 'signalOne', aFunction);370 t.is(has__Connect.count, 3, '__connect__ is called when it exists');371 signal(has__Connect, 'signalOne');372 t.is(has__Connect.count, 3, '__connect__ can disconnect the signal');373 var events = {};374 var test_ident = connect(events, "test", function() {375 var fail_ident = connect(events, "fail", function () {376 events.failed = true;377 });378 disconnect(fail_ident);379 signal(events, "fail");380 });381 signal(events, "test");382 t.is(events.failed, undefined, 'disconnected slots do not fire');383 ...
signal.ts
Source:signal.ts
1import * as assert from 'assert';2import { describe, it } from 'mocha';3import { createSignal } from '../../source/common/signal';4async function delay(ms:number = 0) : Promise<void> {5 return new Promise(resolve => {6 setTimeout(resolve, ms);7 });8}9describe('createSignal', () => {10 it('should send a signal to handler', async () => {11 const msgs:string[] = [];12 const signal = createSignal();13 signal.receiver.onSignal(async handler => {14 msgs.push(`received level 0, ${ handler.numReceived() }`);15 });16 msgs.push(`sending, ${ signal.receiver.numReceived() }`);17 await signal.send();18 msgs.push(`sent, ${ signal.receiver.numReceived() }`);19 assert.deepStrictEqual(msgs, [20 'sending, 0',21 'received level 0, 1',22 'sent, 1'23 ]);24 });25 it('should send a signal along handler chain', async () => {26 const msgs:string[] = [];27 const signal = createSignal();28 signal.receiver.onSignal(async handler => {29 msgs.push(`received level 0, ${ handler.numReceived() }`);30 });31 msgs.push(`level 0, ${ signal.receiver.numReceived() }`);32 new Promise<void>(async resolve => {33 const receiver = signal.receiver.extend().onSignal(async () => {34 msgs.push(`received level 1, ${ receiver.numReceived() }`);35 resolve();36 });37 msgs.push(`level 1, ${ receiver.numReceived() }`);38 await new Promise<void>(resolve2 => {39 const receiver2 = receiver.extend().onSignal(async () => {40 msgs.push(`received level 2, ${ receiver2.numReceived() }`);41 resolve2();42 });43 msgs.push(`level 2, ${ receiver.numReceived() }`);44 });45 msgs.push('resolved p2');46 })47 .then(() => msgs.push('resolved p1'));48 msgs.push(`sending, ${ signal.receiver.numReceived() }`);49 await signal.send();50 msgs.push(`sent, ${ signal.receiver.numReceived() }`);51 assert.deepStrictEqual(msgs, [52 'level 0, 0',53 'level 1, 0',54 'level 2, 0',55 'sending, 0',56 'received level 2, 1',57 'resolved p2',58 'received level 1, 1',59 'resolved p1',60 'received level 0, 1',61 'sent, 1'62 ]);63 });64 it('should handle ephemeral handler chains', async () => {65 const msgs:string[] = [];66 const signal = createSignal();67 signal.receiver.onSignal(async () => {68 msgs.push(`received level 0, ${ signal.receiver.numReceived() }`);69 });70 msgs.push(`level 0, ${ signal.receiver.numReceived() }`);71 signal.receiver72 .extendWhile(receiver => new Promise(resolve => {73 receiver.onSignal(async () => {74 msgs.push(`received level 1, ${ receiver.numReceived() }`)75 resolve('foo');76 });77 msgs.push(`level 1, ${ receiver.numReceived() }`);78 receiver79 .extendWhile(async receiver2 => {80 receiver2.onSignal(async () => {81 msgs.push(`received level 2, ${ receiver2.numReceived() }`);82 });83 msgs.push(`level 2, ${ receiver2.numReceived() }`);84 return 'bar';85 })86 .then(value => msgs.push(`resolved p2 ${ value }`));87 }))88 .then(value => msgs.push(`resolved p1 ${ value }`));89 await delay();90 msgs.push(`sending, ${ signal.receiver.numReceived() }`);91 await signal.send();92 msgs.push(`sent, ${ signal.receiver.numReceived() }`);93 assert.deepStrictEqual(msgs, [94 'level 0, 0',95 'level 1, 0',96 'level 2, 0',97 'resolved p2 bar',98 'sending, 0',99 'received level 1, 1',100 'received level 0, 1',101 'resolved p1 foo',102 'sent, 1'103 ]);104 });105 it('should handle ephemeral handler chains with rejected values', async () => {106 const msgs:string[] = [];107 const signal = createSignal();108 signal.receiver.onSignal(async () => {109 msgs.push(`received level 0, ${ signal.receiver.numReceived() }`);110 });111 msgs.push(`level 0, ${ signal.receiver.numReceived() }`);112 signal.receiver113 .extendWhile(receiver => new Promise(resolve => {114 receiver.onSignal(async () => {115 msgs.push(`received level 1, ${ receiver.numReceived() }`)116 resolve('foo');117 });118 msgs.push(`level 1, ${ receiver.numReceived() }`);119 receiver120 .extendWhile(async receiver2 => {121 receiver2.onSignal(async () => {122 msgs.push(`received level 2, ${ receiver2.numReceived() }`);123 });124 msgs.push(`level 2, ${ receiver2.numReceived() }`);125 throw new Error('bar');126 })127 .then(128 value => msgs.push(`resolved p2 ${ value }`),129 reason => msgs.push(`rejected p2 ${ String(reason) }`)130 );131 }))132 .then(value => msgs.push(`resolved p1 ${ value }`));133 await delay();134 msgs.push(`sending, ${ signal.receiver.numReceived() }`);135 await signal.send();136 msgs.push(`sent, ${ signal.receiver.numReceived() }`);137 assert.deepStrictEqual(msgs, [138 'level 0, 0',139 'level 1, 0',140 'level 2, 0',141 'rejected p2 Error: bar',142 'sending, 0',143 'received level 1, 1',144 'received level 0, 1',145 'resolved p1 foo',146 'sent, 1'147 ]);148 });149 it('should handle delegated handler chains', async () => {150 const msgs:string[] = [];151 const signal = createSignal();152 signal.receiver.onSignal(async handler => {153 msgs.push(`received level 0, ${ handler.numReceived() }`);154 });155 msgs.push(`level 0, ${ signal.receiver.numReceived() }`);156 new Promise(async resolve => {157 const receiver = signal.receiver.delegate().onSignal(async () => {158 msgs.push(`received level 1, ${ receiver.numReceived() }`);159 resolve('baz');160 });161 msgs.push(`level 1, ${ receiver.numReceived() }`);162 const value2 = await new Promise(resolve2 => {163 const receiver2 = receiver.delegate().onSignal(async () => {164 msgs.push(`received level 2, ${ receiver2.numReceived() }`);165 resolve2('foo');166 });167 msgs.push(`level 2, ${ receiver.numReceived() }`);168 });169 msgs.push(`resolved p2 ${ value2 }`);170 resolve('bar');171 })172 .then(value => msgs.push(`resolved p1 ${ value }`));173 msgs.push(`sending, ${ signal.receiver.numReceived() }`);174 await signal.send();175 msgs.push(`sent, ${ signal.receiver.numReceived() }`);176 assert.deepStrictEqual(msgs, [177 'level 0, 0',178 'level 1, 0',179 'level 2, 0',180 'sending, 0',181 'received level 2, 1',182 'resolved p2 foo',183 'resolved p1 bar',184 'sent, 1'185 ]);186 });187 it('should handle ephemeral delegated handler chains', async () => {188 const msgs:string[] = [];189 const signal = createSignal();190 signal.receiver.onSignal(async () => {191 msgs.push(`received level 0, ${ signal.receiver.numReceived() }`);192 });193 msgs.push(`level 0, ${ signal.receiver.numReceived() }`);194 signal.receiver195 .delegateWhile(receiver => new Promise(resolve => {196 receiver.onSignal(async () => {197 msgs.push(`received level 1, ${ receiver.numReceived() }`)198 resolve('foo');199 });200 msgs.push(`level 1, ${ receiver.numReceived() }`);201 receiver202 .delegateWhile(async receiver2 => {203 receiver2.onSignal(async () => {204 msgs.push(`received level 2, ${ receiver2.numReceived() }`);205 });206 msgs.push(`level 2, ${ receiver2.numReceived() }`);207 return 'bar';208 })209 .then(value => msgs.push(`resolved p2 ${ value }`));210 }))211 .then(value => msgs.push(`resolved p1 ${ value }`));212 await delay();213 msgs.push(`sending, ${ signal.receiver.numReceived() }`);214 await signal.send();215 msgs.push(`sent, ${ signal.receiver.numReceived() }`);216 assert.deepStrictEqual(msgs, [217 'level 0, 0',218 'level 1, 0',219 'level 2, 0',220 'resolved p2 bar',221 'sending, 0',222 'received level 1, 1',223 'resolved p1 foo',224 'sent, 1'225 ]);226 });227 it('should handle ephemeral delegated handler chains with rejected values', async () => {228 const msgs:string[] = [];229 const signal = createSignal();230 signal.receiver.onSignal(async () => {231 msgs.push(`received level 0, ${ signal.receiver.numReceived() }`);232 });233 msgs.push(`level 0, ${ signal.receiver.numReceived() }`);234 signal.receiver235 .delegateWhile(receiver => new Promise(resolve => {236 receiver.onSignal(async () => {237 msgs.push(`received level 1, ${ receiver.numReceived() }`)238 resolve('foo');239 });240 msgs.push(`level 1, ${ receiver.numReceived() }`);241 receiver242 .delegateWhile(async receiver2 => {243 receiver2.onSignal(async () => {244 msgs.push(`received level 2, ${ receiver2.numReceived() }`);245 });246 msgs.push(`level 2, ${ receiver2.numReceived() }`);247 throw new Error('bar');248 })249 .then(250 value => msgs.push(`resolved p2 ${ value }`),251 reason => msgs.push(`rejected p2 ${ String(reason) }`)252 );253 }))254 .then(value => msgs.push(`resolved p1 ${ value }`));255 await delay();256 msgs.push(`sending, ${ signal.receiver.numReceived() }`);257 await signal.send();258 msgs.push(`sent, ${ signal.receiver.numReceived() }`);259 assert.deepStrictEqual(msgs, [260 'level 0, 0',261 'level 1, 0',262 'level 2, 0',263 'rejected p2 Error: bar',264 'sending, 0',265 'received level 1, 1',266 'resolved p1 foo',267 'sent, 1'268 ]);269 });270 it('should propagate signals irrespective of handling errors', async () => {271 const msgs:string[] = [];272 const signal = createSignal();273 signal.receiver274 .onSignal(async handler => {275 msgs.push(`received level 0, ${ handler.numReceived() }`);276 })277 .extend()278 .onSignal(handler => {279 msgs.push(`received level 1, ${ handler.numReceived() }`);280 throw new Error()281 });282 msgs.push(`sending, ${ signal.receiver.numReceived() }`);283 await signal.send();284 msgs.push(`sent, ${ signal.receiver.numReceived() }`);285 assert.deepStrictEqual(msgs, [286 'sending, 0',287 'received level 1, 1',288 'received level 0, 1',289 'sent, 1'290 ]);291 });...
SignalBinding.js
Source:SignalBinding.js
1/**2* @author Miller Medeiros http://millermedeiros.github.com/js-signals/3* @author Richard Davey <rich@photonstorm.com>4* @copyright 2016 Photon Storm Ltd.5* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}6*/7/**8* Object that represents a binding between a Signal and a listener function.9* This is an internal constructor and shouldn't be created directly.10* Inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.11* 12* @class Phaser.SignalBinding13* @constructor14* @param {Phaser.Signal} signal - Reference to Signal object that listener is currently bound to.15* @param {function} listener - Handler function bound to the signal.16* @param {boolean} isOnce - If binding should be executed just once.17* @param {object} [listenerContext=null] - Context on which listener will be executed (object that should represent the `this` variable inside listener function).18* @param {number} [priority] - The priority level of the event listener. (default = 0).19* @param {...any} [args=(none)] - Additional arguments to pass to the callback (listener) function. They will be appended after any arguments usually dispatched.20*/21Phaser.SignalBinding = function (signal, listener, isOnce, listenerContext, priority, args) {22 /**23 * @property {Phaser.Game} _listener - Handler function bound to the signal.24 * @private25 */26 this._listener = listener;27 if (isOnce)28 {29 this._isOnce = true;30 }31 if (listenerContext != null) /* not null/undefined */32 {33 this.context = listenerContext;34 }35 /**36 * @property {Phaser.Signal} _signal - Reference to Signal object that listener is currently bound to.37 * @private38 */39 this._signal = signal;40 if (priority)41 {42 this._priority = priority;43 }44 if (args && args.length)45 {46 this._args = args;47 }48};49Phaser.SignalBinding.prototype = {50 /**51 * @property {?object} context - Context on which listener will be executed (object that should represent the `this` variable inside listener function).52 */53 context: null,54 /**55 * @property {boolean} _isOnce - If binding should be executed just once.56 * @private57 */58 _isOnce: false,59 /**60 * @property {number} _priority - Listener priority.61 * @private62 */63 _priority: 0,64 /**65 * @property {array} _args - Listener arguments.66 * @private67 */68 _args: null,69 /**70 * @property {number} callCount - The number of times the handler function has been called.71 */72 callCount: 0,73 /**74 * If binding is active and should be executed.75 * @property {boolean} active76 * @default77 */78 active: true,79 /**80 * Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute` (curried parameters).81 * @property {array|null} params82 * @default83 */84 params: null,85 /**86 * Call listener passing arbitrary parameters.87 * If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.88 * @method Phaser.SignalBinding#execute89 * @param {any[]} [paramsArr] - Array of parameters that should be passed to the listener.90 * @return {any} Value returned by the listener.91 */92 execute: function(paramsArr) {93 var handlerReturn, params;94 if (this.active && !!this._listener)95 {96 params = this.params ? this.params.concat(paramsArr) : paramsArr;97 if (this._args)98 {99 params = params.concat(this._args);100 }101 handlerReturn = this._listener.apply(this.context, params);102 this.callCount++;103 if (this._isOnce)104 {105 this.detach();106 }107 }108 return handlerReturn;109 },110 /**111 * Detach binding from signal.112 * alias to: @see mySignal.remove(myBinding.getListener());113 * @method Phaser.SignalBinding#detach114 * @return {function|null} Handler function bound to the signal or `null` if binding was previously detached.115 */116 detach: function () {117 return this.isBound() ? this._signal.remove(this._listener, this.context) : null;118 },119 /**120 * @method Phaser.SignalBinding#isBound121 * @return {boolean} True if binding is still bound to the signal and has a listener.122 */123 isBound: function () {124 return (!!this._signal && !!this._listener);125 },126 /**127 * @method Phaser.SignalBinding#isOnce128 * @return {boolean} If SignalBinding will only be executed once.129 */130 isOnce: function () {131 return this._isOnce;132 },133 /**134 * @method Phaser.SignalBinding#getListener135 * @return {function} Handler function bound to the signal.136 */137 getListener: function () {138 return this._listener;139 },140 /**141 * @method Phaser.SignalBinding#getSignal142 * @return {Phaser.Signal} Signal that listener is currently bound to.143 */144 getSignal: function () {145 return this._signal;146 },147 /**148 * Delete instance properties149 * @method Phaser.SignalBinding#_destroy150 * @private151 */152 _destroy: function () {153 delete this._signal;154 delete this._listener;155 delete this.context;156 },157 /**158 * @method Phaser.SignalBinding#toString159 * @return {string} String representation of the object.160 */161 toString: function () {162 return '[Phaser.SignalBinding isOnce:' + this._isOnce +', isBound:'+ this.isBound() +', active:' + this.active + ']';163 }164};...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) return console.error(err);4 wpt.getTestStatus(data.data.testId, function(err, data) {5 if (err) return console.error(err);6 console.log(data);7 });8});9{ statusCode: 200,10 { statusCode: 200,11 { testId: '150211_0H_9',
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if (err) {4 console.log('Error: ' + err);5 } else {6 console.log('User ID: ' + data.user);7 console.log('Test ID: ' + data.testId);8 }9});10 if (err) {11 console.log('Error: ' + err);12 } else {13 console.log('Test Status: ' + data.statusText);14 }15});16 if (err) {17 console.log('Error: ' + err);18 } else {19 console.log('Test Results: ' + data);20 }21});22wpt.getLocations(function(err, data) {23 if (err) {24 console.log('Error: ' + err);25 } else {26 console.log('Locations: ' + data);27 }28});29wpt.getTesters(function(err, data) {30 if (err) {31 console.log('Error: ' + err);32 } else {33 console.log('Testers: ' + data);34 }35});36wpt.getLocations(function(err, data) {37 if (err) {38 console.log('Error: ' + err);39 } else {40 console.log('Locations: ' + data);41 }42});43wpt.getTesters(function(err, data) {44 if (err) {45 console.log('Error: ' + err);46 } else {47 console.log('Testers: ' + data);48 }49});50wpt.getTesters(function(err, data) {51 if (err) {52 console.log('Error: ' + err);53 } else {54 console.log('Testers: ' + data);55 }56});
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3}, function (err, data) {4 if (err) return console.error(err);5 console.log('Test status:', data.statusText);6 console.log('Test ID:', data.data.testId);7 wpt.getTestResults(data.data.testId, function (err, data) {8 if (err) return console.error(err);9 console.log('Test results:', data);10 });11});12WebPageTest.prototype.signal = function (testId, signal, callback) {13 var options = {14 qs: {15 }16 };17 request.get(options, function (err, res, body) {18 if (err) return callback(err);19 if (res.statusCode !== 200) return callback(new Error(body));20 try {21 body = JSON.parse(body);22 } catch (e) {23 return callback(e);24 }25 callback(null, body);26 });27};
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.signal('testId', 'stop', function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7wpt.signal('testId', 'abort', function(err, data) {8 if (err) return console.error(err);9 console.log(data);10});11wpt.signal('testId', 'run', function(err, data) {12 if (err) return console.error(err);13 console.log(data);14});15wpt.signal('testId', 'rerun', function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19wpt.signal('testId', 'delete', function(err, data) {20 if (err) return console.error(err);21 console.log(data);22});23wpt.signal('testId', 'deleteall', function(err, data) {24 if (err) return console.error(err);25 console.log(data);26});27wpt.signal('testId', 'deleteallbutfirst', function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});31wpt.signal('testId', 'deleteallbutlast', function(err, data) {32 if (err) return console.error(err);33 console.log(data);34});35wpt.signal('testId', 'deleteallbutmedian', function(err, data) {36 if (err) return console.error(err);37 console.log(data);38});39wpt.signal('testId', 'deleteallbutfirstview', function(err, data) {40 if (err) return console.error(err);41 console.log(data);42});43wpt.signal('testId', 'deleteallbutlastview', function(err, data) {44 if (err) return console.error(err);45 console.log(data);46});
Using AI Code Generation
1var wpt = require('wpt');2var wptObj = new wpt();3wptObj.signal('test', 'stop', function(err, data){4 if(err){5 console.log(err);6 } else {7 console.log(data);8 }9});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!