How to use addListener method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

tests.js

Source:tests.js Github

copy

Full Screen

...36 });37 test('allows you to fetch listeners by regex', function ()38 {39 var check = [];40 ee.addListener('foo', function() { check.push(1); });41 ee.addListener('bar', function() { check.push(2); return 'bar'; });42 ee.addListener('baz', function() { check.push(3); return 'baz'; });43 var listeners = ee.getListeners(/ba[rz]/);44 assert.strictEqual(listeners.bar.length + listeners.baz.length, 2);45 assert.strictEqual(listeners.bar[0].listener(), 'bar');46 assert.strictEqual(listeners.baz[0].listener(), 'baz');47 });48 });49 suite('flattenListeners', function () {50 var ee;51 var fn1 = function(){};52 var fn2 = function(){};53 var fn3 = function(){};54 setup(function () {55 ee = new EventEmitter();56 });57 test('takes an array of objects and returns an array of functions', function () {58 var input = [59 {listener: fn1},60 {listener: fn2},61 {listener: fn3}62 ];63 var output = ee.flattenListeners(input);64 assert.deepEqual(output, [fn1, fn2, fn3]);65 });66 test('if given an empty array, an empty array is returned', function () {67 var output = ee.flattenListeners([]);68 assert.deepEqual(output, []);69 });70 });71 suite('addListener', function() {72 var ee;73 var fn1 = function(){};74 var fn2 = function(){};75 setup(function() {76 ee = new EventEmitter();77 });78 test('adds a listener to the specified event', function() {79 ee.addListener('foo', fn1);80 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1]);81 });82 test('does not allow duplicate listeners', function() {83 ee.addListener('bar', fn1);84 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1]);85 ee.addListener('bar', fn2);86 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1, fn2]);87 ee.addListener('bar', fn1);88 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1, fn2]);89 });90 test('allows you to add listeners by regex', function ()91 {92 var check = [];93 ee.defineEvents(['bar', 'baz']);94 ee.addListener('foo', function() { check.push(1); });95 ee.addListener(/ba[rz]/, function() { check.push(2); });96 ee.emitEvent(/ba[rz]/);97 assert.strictEqual(flattenCheck(check), '2,2');98 });99 });100 suite('addOnceListener', function () {101 var ee;102 var counter;103 var fn1 = function() { counter++; };104 setup(function () {105 ee = new EventEmitter();106 counter = 0;107 });108 test('once listeners can be added', function () {109 ee.addOnceListener('foo', fn1);110 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1]);111 });112 test('listeners are only executed once', function () {113 ee.addOnceListener('foo', fn1);114 ee.emitEvent('foo');115 ee.emitEvent('foo');116 ee.emitEvent('foo');117 assert.strictEqual(counter, 1);118 });119 test('listeners can be removed', function () {120 ee.addOnceListener('foo', fn1);121 ee.removeListener('foo', fn1);122 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);123 });124 test('can not cause infinite recursion', function () {125 ee.addOnceListener('foo', function() {126 counter += 1;127 this.emitEvent('foo');128 });129 ee.trigger('foo');130 assert.strictEqual(counter, 1);131 });132 });133 suite('removeListener', function() {134 var ee;135 var fn1 = function(){};136 var fn2 = function(){};137 var fn3 = function(){};138 var fn4 = function(){};139 var fn5 = function(){};140 var fnX = function(){};141 setup(function() {142 ee = new EventEmitter();143 });144 test('does nothing when the listener is not found', function() {145 var orig = ee.getListeners('foo').length;146 ee.removeListener('foo', fn1);147 assert.lengthOf(ee.getListeners('foo'), orig);148 });149 test('can handle removing events that have not been added', function() {150 assert.notProperty(ee, '_events');151 ee.removeEvent('foo');152 assert.property(ee, '_events');153 assert.isObject(ee._events);154 });155 test('actually removes events', function() {156 ee.removeEvent('foo');157 assert.notDeepProperty(ee, '_events.foo');158 });159 test('removes listeners', function() {160 var listeners = ee.getListeners('bar');161 ee.addListener('bar', fn1);162 ee.addListener('bar', fn2);163 ee.addListener('bar', fn3);164 ee.addListener('bar', fn3); // Make sure doubling up does nothing165 ee.addListener('bar', fn4);166 assert.deepEqual(ee.flattenListeners(listeners), [fn1, fn2, fn3, fn4]);167 ee.removeListener('bar', fn3);168 assert.deepEqual(ee.flattenListeners(listeners), [fn1, fn2, fn4]);169 ee.removeListener('bar', fnX);170 assert.deepEqual(ee.flattenListeners(listeners), [fn1, fn2, fn4]);171 ee.removeListener('bar', fn1);172 assert.deepEqual(ee.flattenListeners(listeners), [fn2, fn4]);173 ee.removeListener('bar', fn4);174 assert.deepEqual(ee.flattenListeners(listeners), [fn2]);175 ee.removeListener('bar', fn2);176 assert.deepEqual(ee.flattenListeners(ee._events.bar), []);177 });178 test('removes with a regex', function() {179 ee.addListeners({180 foo: [fn1, fn2, fn3, fn4, fn5],181 bar: [fn1, fn2, fn3, fn4, fn5],182 baz: [fn1, fn2, fn3, fn4, fn5]183 });184 ee.removeListener(/ba[rz]/, fn3);185 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3, fn2, fn1]);186 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn5, fn4, fn2, fn1]);187 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5, fn4, fn2, fn1]);188 });189 });190 suite('getListenersAsObject', function () {191 var ee;192 setup(function() {193 ee = new EventEmitter();194 ee.addListener('bar', function(){});195 ee.addListener('baz', function(){});196 });197 test('returns an object for strings', function () {198 var listeners = ee.getListenersAsObject('bar');199 assert.isObject(listeners);200 assert.lengthOf(listeners.bar, 1);201 });202 test('returns an object for regexs', function () {203 var listeners = ee.getListenersAsObject(/ba[rz]/);204 assert.isObject(listeners);205 assert.lengthOf(listeners.bar, 1);206 assert.lengthOf(listeners.baz, 1);207 });208 });209 suite('defineEvent', function () {210 var ee;211 setup(function() {212 ee = new EventEmitter();213 });214 test('defines an event when there is nothing else inside', function () {215 ee.defineEvent('foo');216 assert.isArray(ee._events.foo);217 });218 test('defines an event when there are other events already', function () {219 var f = function(){};220 ee.addListener('foo', f);221 ee.defineEvent('bar');222 assert.deepEqual(ee.flattenListeners(ee._events.foo), [f]);223 assert.isArray(ee._events.bar);224 });225 test('does not overwrite existing events', function () {226 var f = function(){};227 ee.addListener('foo', f);228 ee.defineEvent('foo');229 assert.deepEqual(ee.flattenListeners(ee._events.foo), [f]);230 });231 });232 suite('defineEvents', function () {233 var ee;234 setup(function() {235 ee = new EventEmitter();236 });237 test('defines multiple events', function () {238 ee.defineEvents(['foo', 'bar']);239 assert.isArray(ee._events.foo, []);240 assert.isArray(ee._events.bar, []);241 });242 });243 suite('removeEvent', function() {244 var ee;245 var fn1 = function(){};246 var fn2 = function(){};247 var fn3 = function(){};248 var fn4 = function(){};249 var fn5 = function(){};250 setup(function() {251 ee = new EventEmitter();252 ee.addListener('foo', fn1);253 ee.addListener('foo', fn2);254 ee.addListener('bar', fn3);255 ee.addListener('bar', fn4);256 ee.addListener('baz', fn5);257 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn2]);258 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn3, fn4]);259 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5]);260 });261 test('removes all listeners for the specified event', function() {262 ee.removeEvent('bar');263 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn2]);264 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);265 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5]);266 ee.removeEvent('baz');267 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn2]);268 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);269 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), []);270 });271 test('removes all events when no event is specified', function() {272 ee.removeEvent();273 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);274 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);275 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), []);276 });277 test('removes listeners when passed a regex', function ()278 {279 var check = [];280 ee.removeEvent();281 ee.addListener('foo', function() { check.push(1); return 'foo'; });282 ee.addListener('bar', function() { check.push(2); return 'bar'; });283 ee.addListener('baz', function() { check.push(3); return 'baz'; });284 ee.removeEvent(/ba[rz]/);285 var listeners = ee.getListeners('foo');286 assert.lengthOf(listeners, 1);287 assert.strictEqual(listeners[0].listener(), 'foo');288 });289 });290 suite('emitEvent', function() {291 var ee;292 setup(function() {293 ee = new EventEmitter();294 });295 test('executes attached listeners', function() {296 var run = false;297 ee.addListener('foo', function() {298 run = true;299 });300 ee.emitEvent('foo');301 assert.isTrue(run);302 });303 test('executes attached with a single argument', function() {304 var key = null;305 ee.addListener('bar', function(a) {306 key = a;307 });308 ee.emitEvent('bar', [50]);309 assert.strictEqual(key, 50);310 ee.emit('bar', 60);311 assert.strictEqual(key, 60);312 });313 test('executes attached with arguments', function() {314 var key = null;315 ee.addListener('bar2', function(a, b) {316 key = a + b;317 });318 ee.emitEvent('bar2', [40, 2]);319 assert.strictEqual(key, 42);320 });321 test('executes multiple listeners', function() {322 var check = [];323 ee.addListener('baz', function() { check.push(1); });324 ee.addListener('baz', function() { check.push(2); });325 ee.addListener('baz', function() { check.push(3); });326 ee.addListener('baz', function() { check.push(4); });327 ee.addListener('baz', function() { check.push(5); });328 ee.emitEvent('baz');329 assert.strictEqual(flattenCheck(check), '1,2,3,4,5');330 });331 test('executes multiple listeners after one has been removed', function() {332 var check = [];333 var toRemove = function() { check.push('R'); };334 ee.addListener('baz', function() { check.push(1); });335 ee.addListener('baz', function() { check.push(2); });336 ee.addListener('baz', toRemove);337 ee.addListener('baz', function() { check.push(3); });338 ee.addListener('baz', function() { check.push(4); });339 ee.removeListener('baz', toRemove);340 ee.emitEvent('baz');341 assert.strictEqual(flattenCheck(check), '1,2,3,4');342 });343 test('executes multiple listeners and removes those that return true', function() {344 var check = [];345 ee.addListener('baz', function() { check.push(1); });346 ee.addListener('baz', function() { check.push(2); return true; });347 ee.addListener('baz', function() { check.push(3); return false; });348 ee.addListener('baz', function() { check.push(4); return 1; });349 ee.addListener('baz', function() { check.push(5); return true; });350 ee.emitEvent('baz');351 ee.emitEvent('baz');352 assert.strictEqual(flattenCheck(check), '1,1,2,3,3,4,4,5');353 });354 test('can remove listeners that return true and also define another listener within them', function () {355 var check = [];356 ee.addListener('baz', function() { check.push(1); });357 ee.addListener('baz', function() {358 ee.addListener('baz', function() {359 check.push(2);360 });361 check.push(3);362 return true;363 });364 ee.addListener('baz', function() { check.push(4); return false; });365 ee.addListener('baz', function() { check.push(5); return 1; });366 ee.addListener('baz', function() { check.push(6); return true; });367 ee.emitEvent('baz');368 ee.emitEvent('baz');369 assert.strictEqual(flattenCheck(check), '1,1,2,3,4,4,5,5,6');370 });371 test('executes all listeners that match a regular expression', function ()372 {373 var check = [];374 ee.addListener('foo', function() { check.push(1); });375 ee.addListener('bar', function() { check.push(2); });376 ee.addListener('baz', function() { check.push(3); });377 ee.emitEvent(/ba[rz]/);378 assert.strictEqual(flattenCheck(check), '2,3');379 });380 test('global object is defined', function()381 {382 ee.addListener('foo', function() {383 assert.equal(this, ee);384 });385 ee.emitEvent('foo');386 });387 });388 suite('manipulateListeners', function() {389 var ee;390 var fn1 = function(){};391 var fn2 = function(){};392 var fn3 = function(){};393 var fn4 = function(){};394 var fn5 = function(){};395 setup(function() {396 ee = new EventEmitter();397 });398 test('manipulates multiple with an array', function() {399 ee.manipulateListeners(false, 'foo', [fn1, fn2, fn3, fn4, fn5]);400 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3, fn2, fn1]);401 ee.manipulateListeners(true, 'foo', [fn1, fn2]);402 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3]);403 ee.manipulateListeners(true, 'foo', [fn3, fn5]);404 ee.manipulateListeners(false, 'foo', [fn4, fn1]);405 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn4, fn1]);406 ee.manipulateListeners(true, 'foo', [fn4, fn1]);407 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);408 });409 test('manipulates with an object', function() {410 ee.manipulateListeners(false, {411 foo: [fn1, fn2, fn3],412 bar: fn4413 });414 ee.manipulateListeners(false, {415 bar: [fn5, fn1]416 });417 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn3, fn2, fn1]);418 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn4, fn1, fn5]);419 ee.manipulateListeners(true, {420 foo: fn1,421 bar: [fn5, fn4]422 });423 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn3, fn2]);424 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn1]);425 ee.manipulateListeners(true, {426 foo: [fn3, fn2],427 bar: fn1428 });429 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);430 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);431 });432 test('does not execute listeners just after they are added in another listeners', function() {433 var check = [];434 ee.addListener('baz', function() { check.push(1); });435 ee.addListener('baz', function() { check.push(2); });436 ee.addListener('baz', function() {437 check.push(3);438 ee.addListener('baz', function() {439 check.push(4);440 });441 });442 ee.addListener('baz', function() { check.push(5); });443 ee.addListener('baz', function() { check.push(6); });444 ee.emitEvent('baz');445 assert.strictEqual(flattenCheck(check), '1,2,3,5,6');446 });447 });448 suite('addListeners', function() {449 var ee;450 var fn1 = function(){};451 var fn2 = function(){};452 var fn3 = function(){};453 var fn4 = function(){};454 var fn5 = function(){};455 setup(function() {456 ee = new EventEmitter();457 });458 test('adds with an array', function() {459 ee.addListeners('foo', [fn1, fn2, fn3]);460 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn3, fn2, fn1]);461 ee.addListeners('foo', [fn4, fn5]);462 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn3, fn2, fn1, fn5, fn4]);463 });464 test('adds with an object', function() {465 ee.addListeners({466 foo: fn1,467 bar: [fn2, fn3]468 });469 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1]);470 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn3, fn2]);471 ee.addListeners({472 foo: [fn4],473 bar: fn5474 });475 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1, fn4]);476 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn3, fn2, fn5]);477 });478 test('allows you to add listeners by regex', function ()479 {480 var check = [];481 ee.defineEvents(['bar', 'baz']);482 ee.addListeners('foo', [function() { check.push(1); }]);483 ee.addListeners(/ba[rz]/, [function() { check.push(2); }, function() { check.push(3); }]);484 ee.emitEvent(/ba[rz]/);485 assert.strictEqual(flattenCheck(check), '2,2,3,3');486 });487 });488 suite('removeListeners', function() {489 var ee;490 var fn1 = function(){};491 var fn2 = function(){};492 var fn3 = function(){};493 var fn4 = function(){};494 var fn5 = function(){};495 setup(function() {496 ee = new EventEmitter();497 });498 test('removes with an array', function() {499 ee.addListeners('foo', [fn1, fn2, fn3, fn4, fn5]);500 ee.removeListeners('foo', [fn2, fn3]);501 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn1]);502 ee.removeListeners('foo', [fn5, fn4]);503 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn1]);504 ee.removeListeners('foo', [fn1]);505 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), []);506 });507 test('removes with an object', function() {508 ee.addListeners({509 foo: [fn1, fn2, fn3, fn4, fn5],510 bar: [fn1, fn2, fn3, fn4, fn5]511 });512 ee.removeListeners({513 foo: fn2,514 bar: [fn3, fn4, fn5]515 });516 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3, fn1]);517 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn2, fn1]);518 ee.removeListeners({519 foo: [fn3],520 bar: [fn2, fn1]521 });522 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn1]);523 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), []);524 });525 test('removes with a regex', function() {526 ee.addListeners({527 foo: [fn1, fn2, fn3, fn4, fn5],528 bar: [fn1, fn2, fn3, fn4, fn5],529 baz: [fn1, fn2, fn3, fn4, fn5]530 });531 ee.removeListeners(/ba[rz]/, [fn3, fn4]);532 assert.deepEqual(ee.flattenListeners(ee.getListeners('foo')), [fn5, fn4, fn3, fn2, fn1]);533 assert.deepEqual(ee.flattenListeners(ee.getListeners('bar')), [fn5, fn2, fn1]);534 assert.deepEqual(ee.flattenListeners(ee.getListeners('baz')), [fn5, fn2, fn1]);535 });536 });537 suite('setOnceReturnValue', function() {538 var ee;539 setup(function () {540 ee = new EventEmitter();541 });542 test('will remove if left as default and returning true', function () {543 var check = [];544 ee.addListener('baz', function() { check.push(1); });545 ee.addListener('baz', function() { check.push(2); return true; });546 ee.addListener('baz', function() { check.push(3); return false; });547 ee.addListener('baz', function() { check.push(4); return 1; });548 ee.addListener('baz', function() { check.push(5); return true; });549 ee.emitEvent('baz');550 ee.emitEvent('baz');551 assert.strictEqual(flattenCheck(check), '1,1,2,3,3,4,4,5');552 });553 test('will remove those that return a string when set to that string', function () {554 var check = [];555 ee.setOnceReturnValue('only-once');556 ee.addListener('baz', function() { check.push(1); });557 ee.addListener('baz', function() { check.push(2); return true; });558 ee.addListener('baz', function() { check.push(3); return 'only-once'; });559 ee.addListener('baz', function() { check.push(4); return 1; });560 ee.addListener('baz', function() { check.push(5); return 'only-once'; });561 ee.addListener('baz', function() { check.push(6); return true; });562 ee.emitEvent('baz');563 ee.emitEvent('baz');564 assert.strictEqual(flattenCheck(check), '1,1,2,2,3,4,4,5,6,6');565 });566 test('will not remove those that return a different string to the one that is set', function () {567 var check = [];568 ee.setOnceReturnValue('only-once');569 ee.addListener('baz', function() { check.push(1); });570 ee.addListener('baz', function() { check.push(2); return true; });571 ee.addListener('baz', function() { check.push(3); return 'not-only-once'; });572 ee.addListener('baz', function() { check.push(4); return 1; });573 ee.addListener('baz', function() { check.push(5); return 'only-once'; });574 ee.addListener('baz', function() { check.push(6); return true; });575 ee.emitEvent('baz');576 ee.emitEvent('baz');577 assert.strictEqual(flattenCheck(check), '1,1,2,2,3,3,4,4,5,6,6');578 });579 });580 suite('alias', function () {581 test('that it works when overwriting target method', function () {582 var addListener = EventEmitter.prototype.addListener;583 var res;584 var rand = Math.random();585 EventEmitter.prototype.addListener = function () {586 res = rand;587 };588 var ee = new EventEmitter();...

Full Screen

Full Screen

customEvent.js

Source:customEvent.js Github

copy

Full Screen

...4 * @short Custom events5 * @des ±¾Îļþ·Ç±à¼­Æ÷ºËÐÄÎļþ£¬½öÊÊÓÃÓÚÉú³É¶ÔÓ¦µÄʼþ½Ó¿ÚÎĵµ6 * UEditor±à¼­Æ÷ÖеÄËùÓÐʼþ¼àÌýºÍ´¥·¢¶¼Í³Ò»²ÉÓÃ7 * ''editor''ÊDZ༭Æ÷ʵÀý8 * editor.addListener("eventName",handler) ºÍ editor.fireEvent("eventName")·½Ê½µ÷Óã¬Ö§³Öä¯ÀÀÆ÷Ô­Éúʼþ£¬Èçkeydown,keyup,mousedown,mouseupµÈ9 */10/**11 * ±à¼­Æ÷¼ÓÔØÍê³Éʼþ£¨ºËÐÄ£©£¬Ôڱ༭Æ÷×¼±¸ºÃËùÓÐÔËÐÐÌõ¼þʱ´¥·¢£¬´ó²¿·Ö³¡¾°¿ÉÒÔʹÓÃeditor.ready(fn)È¡´ú¡£12 * @name ready13 * @grammar editor.addListener("ready",fn)14 * @example15 * editor.addListener("ready",function(){16 * //thisΪeditorʵÀý17 * this.setContent("»¶Ó­Ê¹ÓÃUEditor£¡");18 * })19 * //ͬÈçϽӿڷ½Ê½µ÷ÓÃ20 * editor.ready(function(){21 * this.setContent("»¶Ó­Ê¹ÓÃUEditor£¡");22 * })23 */24/**25 * Ñ¡Çø±ä»¯Ê¼þ£¨ºËÐÄ£©£¬µ±Ñ¡Çø³öÏֱ仯ʱ´¥·¢¡£26 * ÔÚUEditorÖУ¬ÈκÎÉæ¼°µ½¹â±ê¸Ä±äµÄ²Ù×÷¶¼»á´¥·¢Ñ¡Çø±ä»¯Ê¼þ£¬¸ÃʼþÖ÷ÒªÓÃÀ´ÊµÏÖ¹¤¾ßÀ¸×´Ì¬·´Éä¡£27 * @name selectionChange28 * @grammar editor.addListener("selectionChange",fn)29 * @grammar editor.fireEvent("selectionChange")30 * @example31 * editor.addListener("selectionChange",function(){32 * //thisΪeditorʵÀý33 * })34 */3536/**37 * ÄÚÈݱ仯ʼþ£¨ºËÐÄ£©£¬µ±±à¼­ÇøÓòÖеÄÎı¾ÄÚÈݳöÏֱ仯ʱ´¥·¢38 * @name contentChange39 * @grammar editor.addListener("contentChange",fn)40 * @grammar editor.fireEvent("contentChange")41 */4243/**44 * Õ³Ìùʼþ£¨ºËÐÄ£©£¬µ±Ê¹ÓÃctr+v¿ì½Ý¼üÕ³Ìù(°üÀ¨Chrome¡¢FFä¯ÀÀÆ÷µÄÓÒ¼üÕ³Ìù)ʱ»á´¥·¢±¾Ê¼þ45 * @name (before|after)Paste46 * @grammar editor.addListener("beforePaste",fn)47 * @desc48 * * beforePaste ÔÚ½«Õ³ÌùµÄÄÚÈÝдµ½±à¼­Æ÷֮ǰ´¥·¢£¬Õâ¸öʼþ´¥·¢Ê±£¬Õ³ÌùµÄÄÚÈÝ»¹Î´Ôڱ༭Æ÷ÄÚÏÔʾ49 * * afterPaste Õ³ÌùµÄÄÚÈÝÒѾ­Ð´µ½±à¼­Æ÷Àï±ßºó´¥·¢50 * @example51 * editor.addListener("beforePaste",function(type,data){52 * //beforePasteʼþ¼àÌýÇø±ðÓÚafterPasteʼþ¼àÌý×îÖ÷ÒªµÄÒ»¸ö·½ÃæÊÇ´æÔÚÒ»¸ödata²ÎÊý£¬53 * //¸Ãdata²ÎÊýÊÇÒ»¸ö¶ÔÏ󣬰üº¬ÊôÐÔhtml¡£54 * //ÈôÓû§ÔÚ´Ë´¦¸ü¸Ä¸ÃhtmlµÄֵʱ£¬½«»áÓ°ÏìÕ³Ìùµ½±à¼­Æ÷ÖеÄÄÚÈÝ,Ö÷ÒªÓÃÓÚÕ³ÌùʱÐèÒªÌØÊâ´¦ÀíµÄһЩ³¡¾°¡£55 * console.log(this.getContent) //this¶¼Êǵ±Ç°±à¼­Æ÷µÄʵÀý56 * //beforeʼþ²ÅÓÃÕâ¸ö²ÎÊý£¬ÓÃÀ´ÔÚд³ö±à¼­Æ÷֮ǰ¶ÔÕ³Ìù½øÀ´µÄÄÚÈݽøÐÐ×îºóµÄÐÞ¸Ä57 * data.html = "ÎÒ°ÑÕ³ÌùÄÚÈݸijÉÁËÕâ¾ä»°";58 * })59 */6061/**62 * ÉèÖÃÄÚÈÝʼþ£¨ºËÐÄ£©£¬µ±µ÷ÓÃsetContent·½·¨Ê±´¥·¢63 * @name (before|after)SetContent64 * @grammar editor.addListener("beforeSetContent",fn)65 * @desc66 * * beforeSetContent ÔÚÄÚÈÝдµ½±à¼­Æ÷֮ǰ´¥·¢67 * * afterSetContent ÄÚÈÝÒѾ­Ð´µ½±à¼­Æ÷Àï±ßºó´¥·¢68 * @example69 * editor.addListener("beforeSetContent",function(type,data){70 * //beforeSetContentʼþ¼àÌýÇø±ðÓÚafterSetContentʼþ¼àÌý×îÖ÷ÒªµÄÒ»¸ö·½ÃæÊÇ´æÔÚÒ»¸ödata²ÎÊý£¬71 * //¸Ãdata²ÎÊýÊÇÒ»¸ö¶ÔÏ󣬰üº¬ÊôÐÔhtml¡£72 * //ÈôÓû§ÔÚ´Ë´¦¸ü¸Ä¸ÃhtmlµÄֵʱ£¬½«»áÓ°ÏìÉèÖõ½±à¼­Æ÷ÖеÄÄÚÈÝ,Ö÷ÒªÓÃÓÚÉèÖÃÄÚÈÝʱÐèÒªÌØÊâ´¦ÀíµÄһЩ³¡¾°¡£73 * data.html = "ÎÒ°ÑÉèÖÃÄÚÈݸijÉÁËÕâ¾ä»°";74 * })75 */7677/**78 * getAllHtmlʼþ£¬µ±µ÷ÓÃgetAllHtml·½·¨Ê±´¥·¢79 * @name getAllHtml80 * @grammar editor.addListener("getAllHtml",fn)81 * @desc82 * * Ö÷ÒªÓÃÀ´¶ÔÓÚÉú³ÉµÄÕû¸öhtml´úÂëÖеÄheadÄÚÈݽøÐж¨ÖÆ£¬±ÈÈçÄãÏë²åÈëÄã×Ô¼ºµÄÑùʽ£¬script±êÇ©µÈ£¬ÓÃÀ´ÔÚչʾʱʹÓÃ83 * @example84 * editor.addListener("getAllHtml",function(type,data){85 * //dataÊÇdocumentÖÐhead²¿·ÖhtmlµÄ·â×°£¬¿Éͨ¹ýdata.htmlÀ´»ñÈ¡¶ÔÓ¦×Ö·û´®¡£86 * //ÐèÒªÐ޸ĵĻ°µÃÖØи³Öµdata.html = '<style type="text/css"> body{margin:0;}</style>';87 * })88 */8990/**91 * ÄÚÈÝÌύʼþ(²å¼þ)£¬µ±ÄÚÈÝÌá½»²å¼þ¼ÓÔز¢µ÷ÓÃÁËautosubmitÃüÁîʱ´¥·¢£¬¶àÓÃÓÚÌύ֮ǰµÄÑéÖ¤92 * @name beforeSubmit93 * @grammar editor.addListener("beforeSubmit",fn) //Èôfn·µ»Øfalse£¬Ôò×èÖ¹±¾´ÎÌá½»94 * @example95 * editor.addListener("beforeSubmit",function(){96 * if(!editor.hasContents()){97 * return false;98 * }99 * })100 */101102/**103 * Èç¹ûץȡԶ³ÌµÄͼƬʧ°ÜÁË£¬¾Í´¥·¢104 * @name catchRemoteError105 * @grammar editor.addListener("catchRemoteError",fn)106 * @example107 * editor.addListener("catchRemoteError",function(){108 * console.log("ץȡʧ°ÜÁË£¡")109 * })110 */111112/**113 * µ±×¥È¡Ô¶³ÌµÄͼƬ³É¹¦²¢»á·µ»ØÉú³ÉͼƬµÄÁ´½Óʱ´¥·¢114 * @name catchRemoterSuccess115 * @grammar editor.addListener("catchRemoterSuccess",fn)116 * @example117 * editor.addListener("catchRemoterSuccess",function(){118 * console.log("ץȡ³É¹¦")119 * })120 */121122/**123 * ±à¼­Ä£Ê½Çл»Ê¼þ£¨²å¼þ£©£¬µ±Ô´ÂëģʽºÍ¸»Îı¾Ä£Ê½·¢ÉúÇл»Ê±´¥·¢Ê¼þ124 * @name sourceModeChanged125 * @grammar editor.addListener("sourceModeChanged",fn)126 * @example127 * editor.addListener("sourceModeChanged",function(type,mode){128 * //mode´ú±íÁ˵±Ç°µÄ±à¼­Ä£Ê½£¬true´ú±íÇл»µ½ÁËÔ´Âëģʽ£¬false´ú±íÇл»µ½Á˸»Îı¾Ä£Ê½129 * })130 */131132/**133 * È«ÆÁÇл»Ê¼þ£¨²å¼þ£©£¬µ±Ö´ÐÐÈ«ÆÁÇл»µÄʱºò´¥·¢Ê¼þ134 * @name fullScreenChanged135 * @grammar editor.addListener("fullScreenChanged",fn)136 * @example137 * editor.addListener("fullScreenChanged",function(type,mode){138 * //mode´ú±íµ±Ç°ÊÇ·ñÈ«ÆÁ£¬true´ú±íÇл»µ½ÁËÈ«ÆÁģʽ£¬false´ú±íÇл»µ½ÁËÆÕͨģʽ139 * })140 */141142/**143 * ×ÖÊý³¬³öÏÞÖÆʼþ£¨²å¼þ£©£¬µ±ÊäÈëµÄ×Ö·ûÊý³¬³öÅäÖÃÏîÅäÖÃʱ´¥·¢144 * @name wordCountOverflow145 * @grammar editor.addListener("wordCountOverflow",fn)146 * @example147 * editor.addListener("wordCountOverflow",function(type,length){148 * console.log(length)149 * })150 */ ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const stf = require('devicefarmer-stf-client');2client.addListener('device', (event, device) => {3 if (event === 'add') {4 console.log('Device %s was added.', device.serial);5 }6});7const stf = require('devicefarmer-stf-client');8client.on('device', (event, device) => {9 if (event === 'add') {10 console.log('Device %s was added.', device.serial);11 }12});13const stf = require('devicefarmer-stf-client');14client.on('device', (event, device) => {15 if (event === 'add') {16 console.log('Device %s was added.', device.serial);17 }18});19const stf = require('devicefarmer-stf-client');20client.on('device', (event, device) => {21 if (event === 'add') {22 console.log('Device %s was added.', device.serial);23 }24});25const stf = require('devicefarmer-stf-client');26client.on('device', (event, device) => {27 if (event === 'add') {28 console.log('Device %s was added.', device.serial);29 }30});31const stf = require('devicefarmer-stf-client');32client.on('device', (event, device) => {33 if (event === 'add') {34 console.log('Device %s was added.', device.serial);35 }36});37const stf = require('devicefarmer-stf-client');

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2var client = stf.connect({ host: 'localhost', port: 7100 });3client.addListener('device', function (device) {4 console.log('Device connected: ' + device.serial);5});6client.addListener('disconnect', function (device) {7 console.log('Device disconnected: ' + device.serial);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('devicefarmer-stf-client');2var stfClient = new client();3stfClient.addListener('deviceConnected', function(device) {4 console.log("Device connected: " + device.serial);5});6stfClient.addListener('deviceDisconnected', function(device) {7 console.log("Device disconnected: " + device.serial);8});9stfClient.start();10var client = require('devicefarmer-stf-client');11var stfClient = new client();12stfClient.start();13var client = require('devicefarmer-stf-client');14var stfClient = new client();15stfClient.addListener('deviceConnected', function(device) {16 console.log("Device connected: " + device.serial);17});18stfClient.addListener('deviceDisconnected', function(device) {19 console.log("Device disconnected: " + device.serial);20});21stfClient.start();22var client = require('devicefarmer-stf-client');23var stfClient = new client();24stfClient.addListener('deviceConnected', function(device) {25 console.log("Device connected: " + device.serial);26});27stfClient.addListener('deviceDisconnected', function(device) {28 console.log("Device disconnected: " + device.serial);29});30stfClient.start();31var client = require('devicefarmer-stf-client');32var stfClient = new client();33stfClient.addListener('deviceConnected', function(device) {34 console.log("Device connected: " + device.serial);35});36stfClient.addListener('deviceDisconnected', function(device) {37 console.log("Device disconnected: " + device.serial);38});39stfClient.start();

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf-client');2client.on('connect', function() {3 console.log('Connected');4 client.addDeviceListener(function(device) {5 console.log(device);6 });7});8client.on('disconnect', function() {9 console.log('Disconnected');10});11client.on('error', function(err) {12 console.error(err);13});14client.addDeviceListener(function(device) {15 console.log(device);16});

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run devicefarmer-stf automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful