How to use changeListener method in devicefarmer-stf

Best JavaScript code snippet using devicefarmer-stf

pyjamas.ui.ChangeListener.js

Source:pyjamas.ui.ChangeListener.js Github

copy

Full Screen

1/* start module: pyjamas.ui.ChangeListener */2$pyjs['loaded_modules']['pyjamas.ui.ChangeListener'] = function (__mod_name__) {3 if($pyjs['loaded_modules']['pyjamas.ui.ChangeListener']['__was_initialized__']) return $pyjs['loaded_modules']['pyjamas.ui.ChangeListener'];4 if(typeof $pyjs['loaded_modules']['pyjamas.ui'] == 'undefined' || !$pyjs['loaded_modules']['pyjamas.ui']['__was_initialized__']) $p['___import___']('pyjamas.ui', null);5 var $m = $pyjs['loaded_modules']['pyjamas.ui.ChangeListener'];6 $m['__repr__'] = function() { return '<module: pyjamas.ui.ChangeListener>'; };7 $m['__was_initialized__'] = true;8 if ((__mod_name__ === null) || (typeof __mod_name__ == 'undefined')) __mod_name__ = 'pyjamas.ui.ChangeListener';9 $m['__name__'] = __mod_name__;10 $m.__track_lines__ = new Array();11 $pyjs['loaded_modules']['pyjamas.ui']['ChangeListener'] = $pyjs['loaded_modules']['pyjamas.ui.ChangeListener'];12 try {13 $m.__track_lines__[1] = 'pyjamas.ui.ChangeListener.py, line 1:\n # Copyright (C) 2009, 2012 Luke Kenneth Casson Leighton <lkcl@lkcl.net>';14 $m.__track_lines__[15] = 'pyjamas.ui.ChangeListener.py, line 15:\n from pyjamas import DOM';15 $m.__track_lines__[16] = 'pyjamas.ui.ChangeListener.py, line 16:\n from pyjamas.ui import Event';16 $m.__track_lines__[19] = 'pyjamas.ui.ChangeListener.py, line 19:\n def fireChangeEvent(listeners, sender, event):';17 $m.__track_lines__[20] = 'pyjamas.ui.ChangeListener.py, line 20:\n etype = DOM.eventGetType(event)';18 $m.__track_lines__[21] = 'pyjamas.ui.ChangeListener.py, line 21:\n if etype != "change":';19 $m.__track_lines__[22] = 'pyjamas.ui.ChangeListener.py, line 22:\n return';20 $m.__track_lines__[23] = 'pyjamas.ui.ChangeListener.py, line 23:\n for listener in listeners:';21 $m.__track_lines__[24] = "pyjamas.ui.ChangeListener.py, line 24:\n if hasattr(listener, 'onChange'):";22 $m.__track_lines__[25] = 'pyjamas.ui.ChangeListener.py, line 25:\n listener.onChange(sender)';23 $m.__track_lines__[27] = 'pyjamas.ui.ChangeListener.py, line 27:\n listener(sender)';24 $m.__track_lines__[30] = 'pyjamas.ui.ChangeListener.py, line 30:\n class ChangeHandler(object):';25 $m.__track_lines__[32] = 'pyjamas.ui.ChangeListener.py, line 32:\n def __init__(self):';26 $m.__track_lines__[34] = 'pyjamas.ui.ChangeListener.py, line 34:\n self._changeListeners = []';27 $m.__track_lines__[35] = 'pyjamas.ui.ChangeListener.py, line 35:\n self.sinkEvents(Event.ONCHANGE)';28 $m.__track_lines__[37] = 'pyjamas.ui.ChangeListener.py, line 37:\n def onBrowserEvent(self, event):';29 $m.__track_lines__[38] = 'pyjamas.ui.ChangeListener.py, line 38:\n etype = DOM.eventGetType(event)';30 $m.__track_lines__[39] = "pyjamas.ui.ChangeListener.py, line 39:\n if etype == 'change':";31 $m.__track_lines__[40] = 'pyjamas.ui.ChangeListener.py, line 40:\n fireChangeEvent(self._changeListeners, self, event)';32 $m.__track_lines__[42] = 'pyjamas.ui.ChangeListener.py, line 42:\n def addChangeListener(self, listener):';33 $m.__track_lines__[43] = 'pyjamas.ui.ChangeListener.py, line 43:\n self._changeListeners.append(listener)';34 $m.__track_lines__[45] = 'pyjamas.ui.ChangeListener.py, line 45:\n def removeChangeListener(self, listener):';35 $m.__track_lines__[46] = 'pyjamas.ui.ChangeListener.py, line 46:\n self._changeListeners.remove(listener)';36 $m.__track_lines__[48] = 'pyjamas.ui.ChangeListener.py, line 48:\n def onChange(self, sender):';37 $m.__track_lines__[49] = 'pyjamas.ui.ChangeListener.py, line 49:\n pass';38 $pyjs['track']['module']='pyjamas.ui.ChangeListener';39 $pyjs['track']['lineno']=1;40 $pyjs['track']['lineno']=15;41 $pyjs['track']={'module':$pyjs['track']['module'],'lineno':$pyjs['track']['lineno']};$pyjs['trackstack']['push']($pyjs['track']);42 $m['DOM'] = $p['___import___']('pyjamas.DOM', 'pyjamas.ui', null, false);43 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);44 $pyjs['track']['lineno']=16;45 $pyjs['track']={'module':$pyjs['track']['module'],'lineno':$pyjs['track']['lineno']};$pyjs['trackstack']['push']($pyjs['track']);46 $m['Event'] = $p['___import___']('pyjamas.ui.Event', 'pyjamas.ui', null, false);47 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);48 $pyjs['track']['lineno']=19;49 $m['fireChangeEvent'] = function(listeners, sender, event) {50 if ($pyjs['options']['arg_count'] && arguments['length'] != 3) $pyjs__exception_func_param(arguments['callee']['__name__'], 3, 3, arguments['length']);51 var $iter1_nextval,$iter1_idx,$iter1_iter,listener,$iter1_array,$pyjs__trackstack_size_1,etype,$iter1_type;52 $pyjs['track']={'module':'pyjamas.ui.ChangeListener','lineno':19};$pyjs['trackstack']['push']($pyjs['track']);53 $pyjs['track']['module']='pyjamas.ui.ChangeListener';54 $pyjs['track']['lineno']=19;55 $pyjs['track']['lineno']=20;56 etype = $m['DOM']['eventGetType'](event);57 $pyjs['track']['lineno']=21;58 if ($p['bool'](!$p['op_eq'](etype, 'change'))) {59 $pyjs['track']['lineno']=22;60 $pyjs['track']['lineno']=22;61 var $pyjs__ret = null;62 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);63 return $pyjs__ret;64 }65 $pyjs['track']['lineno']=23;66 $pyjs__trackstack_size_1=$pyjs['trackstack']['length'];67 $iter1_iter = listeners;68 $iter1_nextval=$p['__iter_prepare']($iter1_iter,false);69 while (typeof($p['__wrapped_next']($iter1_nextval)['$nextval']) != 'undefined') {70 listener = $iter1_nextval['$nextval'];71 $pyjs['track']['lineno']=24;72 if ($p['bool']($p['hasattr'](listener, 'onChange'))) {73 $pyjs['track']['lineno']=25;74 listener['onChange'](sender);75 }76 else {77 $pyjs['track']['lineno']=27;78 listener(sender);79 }80 }81 if ($pyjs['trackstack']['length'] > $pyjs__trackstack_size_1) {82 $pyjs['trackstack'] = $pyjs['trackstack']['slice'](0,$pyjs__trackstack_size_1);83 $pyjs['track'] = $pyjs['trackstack']['slice'](-1)[0];84 }85 $pyjs['track']['module']='pyjamas.ui.ChangeListener';86 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);87 return null;88 };89 $m['fireChangeEvent']['__name__'] = 'fireChangeEvent';90 $m['fireChangeEvent']['__bind_type__'] = 0;91 $m['fireChangeEvent']['__args__'] = [null,null,['listeners'],['sender'],['event']];92 $pyjs['track']['lineno']=30;93 $m['ChangeHandler'] = (function(){94 var $cls_definition = new Object();95 var $method;96 $cls_definition['__module__'] = 'pyjamas.ui.ChangeListener';97 $cls_definition['__md5__'] = '33b7cba2de55bec6e0f2d3d727f08550';98 $pyjs['track']['lineno']=32;99 $method = $pyjs__bind_method2('__init__', function() {100 if (this['__is_instance__'] === true) {101 var self = this;102 if ($pyjs['options']['arg_count'] && arguments['length'] != 0) $pyjs__exception_func_param(arguments['callee']['__name__'], 1, 1, arguments['length']+1);103 } else {104 var self = arguments[0];105 if ($pyjs['options']['arg_is_instance'] && self['__is_instance__'] !== true) $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);106 if ($pyjs['options']['arg_count'] && arguments['length'] != 1) $pyjs__exception_func_param(arguments['callee']['__name__'], 1, 1, arguments['length']);107 }108 if ($pyjs['options']['arg_instance_type']) {109 if (self.prototype['__md5__'] !== '33b7cba2de55bec6e0f2d3d727f08550') {110 if (!$p['_isinstance'](self, arguments['callee']['__class__'])) {111 $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);112 }113 }114 }115 $pyjs['track']={'module':'pyjamas.ui.ChangeListener', 'lineno':32};$pyjs['trackstack']['push']($pyjs['track']);116 $pyjs['track']['module']='pyjamas.ui.ChangeListener';117 $pyjs['track']['lineno']=32;118 $pyjs['track']['lineno']=34;119 self['__is_instance__'] && typeof self['__setattr__'] == 'function' ? self['__setattr__']('_changeListeners', $p['list']([])) : $p['setattr'](self, '_changeListeners', $p['list']([])); 120 $pyjs['track']['lineno']=35;121 self['sinkEvents']($p['getattr']($m['Event'], 'ONCHANGE'));122 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);123 return null;124 }125 , 1, [null,null,['self']]);126 $cls_definition['__init__'] = $method;127 $pyjs['track']['lineno']=37;128 $method = $pyjs__bind_method2('onBrowserEvent', function(event) {129 if (this['__is_instance__'] === true) {130 var self = this;131 if ($pyjs['options']['arg_count'] && arguments['length'] != 1) $pyjs__exception_func_param(arguments['callee']['__name__'], 2, 2, arguments['length']+1);132 } else {133 var self = arguments[0];134 event = arguments[1];135 if ($pyjs['options']['arg_is_instance'] && self['__is_instance__'] !== true) $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);136 if ($pyjs['options']['arg_count'] && arguments['length'] != 2) $pyjs__exception_func_param(arguments['callee']['__name__'], 2, 2, arguments['length']);137 }138 if ($pyjs['options']['arg_instance_type']) {139 if (self.prototype['__md5__'] !== '33b7cba2de55bec6e0f2d3d727f08550') {140 if (!$p['_isinstance'](self, arguments['callee']['__class__'])) {141 $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);142 }143 }144 }145 var etype;146 $pyjs['track']={'module':'pyjamas.ui.ChangeListener', 'lineno':37};$pyjs['trackstack']['push']($pyjs['track']);147 $pyjs['track']['module']='pyjamas.ui.ChangeListener';148 $pyjs['track']['lineno']=37;149 $pyjs['track']['lineno']=38;150 etype = $m['DOM']['eventGetType'](event);151 $pyjs['track']['lineno']=39;152 if ($p['bool']($p['op_eq'](etype, 'change'))) {153 $pyjs['track']['lineno']=40;154 $m['fireChangeEvent']($p['getattr'](self, '_changeListeners'), self, event);155 }156 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);157 return null;158 }159 , 1, [null,null,['self'],['event']]);160 $cls_definition['onBrowserEvent'] = $method;161 $pyjs['track']['lineno']=42;162 $method = $pyjs__bind_method2('addChangeListener', function(listener) {163 if (this['__is_instance__'] === true) {164 var self = this;165 if ($pyjs['options']['arg_count'] && arguments['length'] != 1) $pyjs__exception_func_param(arguments['callee']['__name__'], 2, 2, arguments['length']+1);166 } else {167 var self = arguments[0];168 listener = arguments[1];169 if ($pyjs['options']['arg_is_instance'] && self['__is_instance__'] !== true) $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);170 if ($pyjs['options']['arg_count'] && arguments['length'] != 2) $pyjs__exception_func_param(arguments['callee']['__name__'], 2, 2, arguments['length']);171 }172 if ($pyjs['options']['arg_instance_type']) {173 if (self.prototype['__md5__'] !== '33b7cba2de55bec6e0f2d3d727f08550') {174 if (!$p['_isinstance'](self, arguments['callee']['__class__'])) {175 $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);176 }177 }178 }179 $pyjs['track']={'module':'pyjamas.ui.ChangeListener', 'lineno':42};$pyjs['trackstack']['push']($pyjs['track']);180 $pyjs['track']['module']='pyjamas.ui.ChangeListener';181 $pyjs['track']['lineno']=42;182 $pyjs['track']['lineno']=43;183 self['_changeListeners']['append'](listener);184 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);185 return null;186 }187 , 1, [null,null,['self'],['listener']]);188 $cls_definition['addChangeListener'] = $method;189 $pyjs['track']['lineno']=45;190 $method = $pyjs__bind_method2('removeChangeListener', function(listener) {191 if (this['__is_instance__'] === true) {192 var self = this;193 if ($pyjs['options']['arg_count'] && arguments['length'] != 1) $pyjs__exception_func_param(arguments['callee']['__name__'], 2, 2, arguments['length']+1);194 } else {195 var self = arguments[0];196 listener = arguments[1];197 if ($pyjs['options']['arg_is_instance'] && self['__is_instance__'] !== true) $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);198 if ($pyjs['options']['arg_count'] && arguments['length'] != 2) $pyjs__exception_func_param(arguments['callee']['__name__'], 2, 2, arguments['length']);199 }200 if ($pyjs['options']['arg_instance_type']) {201 if (self.prototype['__md5__'] !== '33b7cba2de55bec6e0f2d3d727f08550') {202 if (!$p['_isinstance'](self, arguments['callee']['__class__'])) {203 $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);204 }205 }206 }207 $pyjs['track']={'module':'pyjamas.ui.ChangeListener', 'lineno':45};$pyjs['trackstack']['push']($pyjs['track']);208 $pyjs['track']['module']='pyjamas.ui.ChangeListener';209 $pyjs['track']['lineno']=45;210 $pyjs['track']['lineno']=46;211 self['_changeListeners']['remove'](listener);212 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);213 return null;214 }215 , 1, [null,null,['self'],['listener']]);216 $cls_definition['removeChangeListener'] = $method;217 $pyjs['track']['lineno']=48;218 $method = $pyjs__bind_method2('onChange', function(sender) {219 if (this['__is_instance__'] === true) {220 var self = this;221 if ($pyjs['options']['arg_count'] && arguments['length'] != 1) $pyjs__exception_func_param(arguments['callee']['__name__'], 2, 2, arguments['length']+1);222 } else {223 var self = arguments[0];224 sender = arguments[1];225 if ($pyjs['options']['arg_is_instance'] && self['__is_instance__'] !== true) $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);226 if ($pyjs['options']['arg_count'] && arguments['length'] != 2) $pyjs__exception_func_param(arguments['callee']['__name__'], 2, 2, arguments['length']);227 }228 if ($pyjs['options']['arg_instance_type']) {229 if (self.prototype['__md5__'] !== '33b7cba2de55bec6e0f2d3d727f08550') {230 if (!$p['_isinstance'](self, arguments['callee']['__class__'])) {231 $pyjs__exception_func_instance_expected(arguments['callee']['__name__'], arguments['callee']['__class__']['__name__'], self);232 }233 }234 }235 $pyjs['track']={'module':'pyjamas.ui.ChangeListener', 'lineno':48};$pyjs['trackstack']['push']($pyjs['track']);236 $pyjs['track']['module']='pyjamas.ui.ChangeListener';237 $pyjs['track']['lineno']=48;238 $pyjs['track']['lineno']=49;239 $pyjs['trackstack']['pop']();$pyjs['track']=$pyjs['trackstack']['pop']();$pyjs['trackstack']['push']($pyjs['track']);240 return null;241 }242 , 1, [null,null,['self'],['sender']]);243 $cls_definition['onChange'] = $method;244 $pyjs['track']['lineno']=30;245 var $bases = new Array($p['object']);246 var $data = $p['dict']();247 for (var $item in $cls_definition) { $data['__setitem__']($item, $cls_definition[$item]); }248 return $p['_create_class']('ChangeHandler', $p['tuple']($bases), $data);249 })();250 } catch ($pyjs_attr_err) {throw $p['_errorMapping']($pyjs_attr_err);};251 return this;252}; /* end pyjamas.ui.ChangeListener */253/* end module: pyjamas.ui.ChangeListener */254/*255PYJS_DEPS: ['pyjamas.DOM', 'pyjamas', 'pyjamas.ui.Event', 'pyjamas.ui']...

Full Screen

Full Screen

ChangesListener.js

Source:ChangesListener.js Github

copy

Full Screen

1/* eslint-disable camelcase */2/* eslint-disable no-underscore-dangle */3/* global MutationObserver */4/* global IntersectionObserver */5/* global document */6import { showError } from './utils';7export function __isNativeEvent(event) {8 const defaultEvents = [9 'click',10 'mouseover',11 'mouseout',12 'keyup',13 'keypress',14 'change',15 'focus',16 'submit'17 ];18 return defaultEvents.indexOf(event) > -1;19}20class ChangesListener {21 constructor({22 answer_id,23 listener_id,24 selector,25 event,26 attributeName,27 active_listener_id28 }) {29 this.answer_id = answer_id;30 this.__tourObject = null;31 this.listener_id = listener_id;32 this.parent_listener = active_listener_id;33 this.selector = selector;34 this.event = event;35 this.attributeName = attributeName;36 }37 get tourJs() {38 return this.__tourObject;39 }40 set tourJs(val) {41 this.__tourObject = val;42 }43 init() {44 if (this.tourJs == null) {45 showError('Сперва задайте значение tourJs');46 return;47 }48 let isBody = false;49 const { event } = this;50 // конфигурация нашего observer:51 let config = { attributes: true, childList: true, characterData: false };52 // выбираем целевой элемент53 let target = document.querySelector(this.selector);54 if (__isNativeEvent(event)) {55 // Обработка клика56 if (event === 'click') {57 this.callback = this.nativeClickListener.bind(this);58 document.addEventListener(event, this.callback, false);59 } else if (target != null) {60 // Обработка остального61 this.callback = this.nativeEventListener.bind(this);62 target.addEventListener(event, this.callback, false);63 } else if (target == null) {64 showError('Ошибка: Элемент отсутствует в DOM: ' + this.selector);65 }66 return;67 }68 // Если элемент не найден в DOM дереве69 if (!target) {70 target = document.body;71 config.subtree = true;72 isBody = true;73 }74 if (isBody === false) {75 let observer;76 let callback;77 switch (event) {78 case 'show':79 callback = this.IntersectionShowCallback;80 break;81 case 'hide':82 callback = this.IntersectionHideCallback;83 break;84 case 'class_change':85 callback = this.classChangeCallback;86 break;87 case 'attr_change':88 callback = this.attributeChangeCallback;89 break;90 case 'text_change':91 config = Object.assign(config, {92 subtree: true,93 characterData: true,94 attributeOldValue: true,95 characterDataOldValue: true96 });97 callback = this.characterDataChangeCallback;98 break;99 case 'children_change':100 config.subtree = true;101 callback = this.childrenChangeCallback;102 break;103 default:104 showError(`Не попал под условия: ${this.selector} - ${event}`);105 return;106 // break;107 }108 if (typeof callback !== 'function') {109 showError('Callback функция не определена!');110 return;111 }112 // если используется IntersectionObserver113 if (['show', 'hide'].indexOf(event) > -1) {114 observer = new IntersectionObserver((entries, context) => {115 entries.forEach(callback.bind(context));116 });117 } else {118 // Если используется MutationObserver119 observer = new MutationObserver((mutations, context) => {120 mutations.forEach(callback.bind(context));121 });122 }123 this.tourJs.__observers[this.listener_id] = observer;124 observer.observe(target, config);125 } else {126 // создаём экземпляр MutationObserver127 const observer = new MutationObserver((mutations, context) => {128 switch (event) {129 case 'show':130 mutations.forEach(this.showCallback.bind(context));131 break;132 case 'hide':133 mutations.forEach(this.hideCallback.bind(context));134 break;135 default:136 showError(`Не попал под условия: ${this.selector} - ${this.event}`);137 this.disconnectListener();138 break;139 }140 });141 // передаём в качестве аргументов целевой элемент и его конфигурацию142 this.tourJs.__observers[this.listener_id] = observer;143 observer.observe(target, config);144 }145 }146 /**147 *148 */149 disconnectListener() {150 const listener = this.tourJs.__observers[this.listener_id];151 if (!listener) {152 showError(`Listener с id ${this.listener_id} не найден`);153 return;154 }155 listener.disconnect();156 }157 sendMessage() {158 this.tourJs.sendMessage({159 listener_id: this.listener_id160 });161 }162 /**163 * Проверяет активен ли тот листенер в чате, который содержал данное "Внешнее событие"164 */165 isParentListenerActive() {166 return this.tourJs.active.listenerId === this.parent_listener;167 }168 /**169 * Callback функция для прослушивания нативных событии JavaScript170 * @param {Event} jsEvent171 */172 nativeEventListener(jsEvent) {173 if (174 jsEvent.target.matches(this.selector) &&175 this.isParentListenerActive()176 ) {177 this.sendMessage();178 jsEvent.target.removeEventListener(this.event, this.callback, false);179 this.destroy();180 }181 }182 /**183 *Callback функция для прослушивания нативных CLICK событии JavaScript184 * @param {Event} jsEvent185 */186 nativeClickListener(jsEvent) {187 if (188 jsEvent.target.matches(this.selector) &&189 this.isParentListenerActive()190 ) {191 this.sendMessage();192 document.removeEventListener(this.event, this.callback);193 this.destroy();194 }195 }196 /**197 * Останавливает слушатели198 */199 destroy() {200 this.tourJs.listenersList.delete(this.answer_id);201 }202 IntersectionShowCallback(changeListener) {203 if (this.isIntersecting) {204 changeListener.sendMessage();205 changeListener.disconnectListener();206 }207 }208 IntersectionHideCallback(changeListener) {209 if (this.intersectionRatio === 0 && this.isIntersecting === false) {210 changeListener.sendMessage();211 changeListener.disconnectListener();212 }213 }214 /**215 * Callback функция когда event == 'show' (показ) и этого элемента нет в DOM216 */217 showCallback(changeListener) {218 if (this.type === 'childList' && this.addedNodes.length > 0) {219 const el = document.querySelector(changeListener.selector);220 if (this.addedNodes[0].isSameNode(el)) {221 changeListener.sendMessage();222 return changeListener.disconnectListener();223 }224 }225 return false;226 }227 hideCallback(changeListener) {228 if (this.type === 'childList' && this.removedNodes.length > 0) {229 const node = this.removedNodes[0];230 if (node.nodeType === 1 && node.matches(changeListener.selector)) {231 changeListener.sendMessage();232 return changeListener.disconnectListener();233 }234 }235 return false;236 }237 classChangeCallback(changeListener) {238 if (this.type === 'attributes' && this.attributeName === 'class') {239 changeListener.sendMessage();240 return changeListener.disconnectListener();241 }242 return false;243 }244 attributeChangeCallback(changeListener) {245 if (246 this.type === 'attributes' &&247 this.attributeName === changeListener.attributeName248 ) {249 changeListener.sendMessage();250 return changeListener.disconnectListener();251 }252 return false;253 }254 characterDataChangeCallback(changeListener) {255 if (this.type === 'characterData' || this.type === 'childList') {256 changeListener.sendMessage();257 changeListener.disconnectListener();258 }259 }260 childrenChangeCallback(changeListener) {261 if (this.type === 'childList') {262 changeListener.sendMessage();263 changeListener.disconnectListener();264 }265 }266}...

Full Screen

Full Screen

BpkAppearance-test.js

Source:BpkAppearance-test.js Github

copy

Full Screen

1/*2 * Backpack - Skyscanner's Design System3 *4 * Copyright 2016-2021 Skyscanner Ltd5 *6 * Licensed under the Apache License, Version 2.0 (the "License");7 * you may not use this file except in compliance with the License.8 * You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18import { eventEmitter as mockedEmitter } from 'react-native-dark-mode';19import subject from './BpkAppearance';20jest.mock('react-native-dark-mode', () => {21 const eventEmitter = (() => {22 let registeredCallback = () => {};23 return {24 on: (event, callback) => {25 registeredCallback = callback;26 },27 trigger: (newMode) => registeredCallback(newMode),28 };29 })();30 return {31 initialMode: 'light',32 eventEmitter,33 };34});35describe('BpkAppearance', () => {36 const initialAppearance = subject.get();37 afterEach(() => {38 subject.set(initialAppearance);39 });40 it('correctly returns initial appearance', () => {41 expect(subject.get()).toEqual({ colorScheme: 'light' });42 });43 it('correctly updates the appearance', () => {44 expect(subject.get()).toEqual({ colorScheme: 'light' });45 });46 it('triggers change listeners', () => {47 const changeListener = jest.fn();48 const changeListener2 = jest.fn();49 try {50 subject.addChangeListener(changeListener);51 subject.addChangeListener(changeListener2);52 subject.set({ colorScheme: 'dark' });53 expect(subject.get()).toEqual({ colorScheme: 'dark' });54 expect(changeListener).toHaveBeenCalledWith({ colorScheme: 'dark' });55 expect(changeListener2).toHaveBeenCalledWith({ colorScheme: 'dark' });56 } finally {57 subject.removeChangeListener(changeListener);58 subject.removeChangeListener(changeListener2);59 }60 });61 it('does not trigger if new preferences are the same', () => {62 const changeListener = jest.fn();63 try {64 subject.addChangeListener(changeListener);65 subject.set({ colorScheme: 'light' });66 expect(changeListener).not.toHaveBeenCalled();67 } finally {68 subject.removeChangeListener(changeListener);69 }70 });71 it('does not duplicate listeners', () => {72 const changeListener = jest.fn();73 try {74 subject.addChangeListener(changeListener);75 subject.addChangeListener(changeListener);76 subject.set({ colorScheme: 'dark' });77 expect(changeListener).toHaveBeenCalledTimes(1);78 } finally {79 subject.removeChangeListener(changeListener);80 }81 });82 it('remove listeners', () => {83 const changeListener = jest.fn();84 subject.addChangeListener(changeListener);85 subject.removeChangeListener(changeListener);86 subject.set({ colorScheme: 'dark' });87 expect(changeListener).not.toHaveBeenCalled();88 });89 it('trigger listeners when system color mode changes', () => {90 const changeListener = jest.fn();91 subject.addChangeListener(changeListener);92 mockedEmitter.trigger('dark');93 expect(changeListener).toHaveBeenCalledWith({ colorScheme: 'dark' });94 subject.removeChangeListener(changeListener);95 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('devicefarmer-stf-client');2var device = stf.device('device-id');3device.changeListener(function(err, data){4 if(err){5 console.log(err);6 }7 else{8 console.log(data);9 }10});

Full Screen

Using AI Code Generation

copy

Full Screen

1var stf = require('devicefarmer-stf');2var device = client.getDevice('device_id');3device.changeListener(function(device){4 console.log(device);5});6var stf = require('devicefarmer-stf');7var device = client.getDevice('device_id');8device.changeListener(function(device){9 console.log(device);10});11var stf = require('devicefarmer-stf');12var device = client.getDevice('device_id');13device.changeListener(function(device){14 console.log(device);15});16var stf = require('devicefarmer-stf');17var device = client.getDevice('device_id');18device.changeListener(function(device){19 console.log(device);20});21var stf = require('devicefarmer-stf');22var device = client.getDevice('device_id');23device.changeListener(function(device){24 console.log(device);25});26var stf = require('devicefarmer-stf');27var device = client.getDevice('device_id');28device.changeListener(function(device){29 console.log(device);30});31var stf = require('devicefarmer-stf');32var device = client.getDevice('device_id');33device.changeListener(function(device){34 console.log(device);35});36var stf = require('devicefarmer-stf');

Full Screen

Using AI Code Generation

copy

Full Screen

1var client = require('devicefarmer-stf-client');2var device = stf.getDevice('deviceid');3device.changeListener(function(err, data) {4 console.log(data);5});6{ serial: 'deviceid',

Full Screen

Using AI Code Generation

copy

Full Screen

1var devicefarmer = require('devicefarmer-stf');2var stf = devicefarmer.connect();3var device = stf.getDevice('deviceID');4device.changeListener(function(err, data) {5 console.log(data);6});7device.getState(function(err, data) {8 console.log(data);9});10device.getInfo(function(err, data) {11 console.log(data);12});13device.getName(function(err, data) {14 console.log(data);15});16device.getBattery(function(err, data) {17 console.log(data);18});19device.getScreenSize(function(err, data) {20 console.log(data);21});22device.getScreenDensity(function(err, data) {23 console.log(data);24});25device.getScreenResolution(function(err, data) {26 console.log(data);27});28device.getScreenRotation(function(err, data) {29 console.log(data);30});31device.getDisplayMetrics(function(err, data) {32 console.log(data);33});34device.getDisplayInfo(function(err, data) {35 console.log(data);36});37device.getPhoneNumber(function(err, data) {38 console.log(data);39});40device.getPhoneOperator(function(err, data) {41 console.log(data);42});43device.getPhoneState(function(err, data) {44 console.log(data);45});46device.getWifiState(function(err, data) {47 console.log(data);48});49device.getNetworkType(function(err, data) {50 console.log(data);51});52device.getRunningProcesses(function(err, data) {53 console.log(data);54});55device.getRunningServices(function(err, data) {56 console.log(data);57});58device.getMemoryInfo(function(err, data) {59 console.log(data);60});61device.getBatteryInfo(function(err, data) {

Full Screen

Using AI Code Generation

copy

Full Screen

1var Client = require('devicefarmer-stf-client');2var adb = require('adbkit');3client.connect().then(function () {4 console.log('connected to stf server');5 client.changeListener().then(function (data) {6 console.log('changeListener called');7 console.log(data);8 if (data.added) {9 console.log('device added');10 console.log(data.added.serial);11 client.connectDevice(data.added.serial).then(function (device) {12 console.log('connected to device');13 console.log(device);14 device.getProperties().then(function (properties) {15 console.log('properties');16 console.log(properties);17 });18 device.getStatus().then(function (status) {19 console.log('status');20 console.log(status);21 });22 });23 }24 });25});

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