How to use cs method in wpt

Best JavaScript code snippet using wpt

grid.js

Source:grid.js Github

copy

Full Screen

1class grid {2 3 constructor(){4 this._gridCells = new Array;5 this._solidCell = new cell(-2,-2);6 this._openCell = new cell(-2,-2);7 this.newGrid();8 }9 10 newGrid() {11 this._openCell._solid = false;12 this._openCell._isDrawn = false;13 this._solidCell._isDrawn = false;14 for (var i = 0; i < mh; i++) {15 for (var j = 0; j < mw; j++) {16 let c = new cell(j,i);17 this.setCell(j, i, c);18 }19 }20 }21 // get a specific cell22 getCell(x,y) { 23 if(x<0 || y<0 || x>=mw || y>=mh) return this._openCell 24 return this._gridCells[ x+ mw* y]; 25 }26 // puts a cell in the grid27 setCell(x,y,gridCell) { this._gridCells[x+ mw* y] = gridCell;}28 // checks to see if the cell in this location is solid29 isSolid(x,y){ return this.getCell(x,y)._solid};30 // checks to see if the cell in this location is open31 isOpen(x,y){ return !this.getCell(x,y)._solid};32 // checks to see if the cell in this location is open33 mustCarve(x,y){ return this.getCell(x,y)._mustCarve};34 // makes the cell in this location open35 setOpen(x,y){ this.getCell(x,y)._solid = false;}36 // makes the cell in this location solid37 setSolid(x,y){ this.getCell(x,y)._solid = true;}38 // puts an item in the cell39 setItem(x,y,o) { this.getCell(x,y)._mapItem = o;}40 // gets an item in the cell41 getItem(x,y) { return this.getCell(x,y)._mapItem;}42 // removes an item in the cell43 removeItem(x,y) { this.getCell(x,y)._mapItem = null; }44 // check if it has an item45 hasItem(x,y) { if( (this.getCell(x,y)._mapItem != null) || (this.isSolid(x,y)) ) return true; else return false;}46 47 // // puts an Monster in the cell48 // setMonster(x,y,o) { this.getCell(x,y)._mapMonster = o;}49 // // gets an Monster in the cell50 // getMonster(x,y) { return this.getCell(x,y)._mapMonster;}51 // // removes an Monster in the cell52 // removeMonster(x,y) { this.getCell(x,y)._mapMonster = null; }53 // // check if it has an Monster54 // hasMonster(x,y) { if( (this.getCell(x,y)._mapMonster != null) || (this.isSolid(x,y)) ) return true; else return false;}55 56 // stops a cell from being carvable57 setNoCarve(x,y){ if(!this.getCell(x,y)._mustCarve) {this.getCell(x,y)._noCarve = true;}}58 setMustCarve(x,y){ this.getCell(x,y)._mustCarve = true;}59 addObjects(n){60 for(let i=0; i<n; i++)61 {62 let i = il.makeItem()63 //console.log(i);64 i.placeObject(); 65 }66 }67 createMap(){68 this.newGrid();69 let i,j,k,l;70 let x,y,w,h;71 for(i=0; i<3; i++){72 for(j=0; j<3; j++){73 if(Math.random()<roomPC)74 {75 w = getRandom(mw/9,Math.floor(mw/4));76 h = getRandom(mh/9,Math.floor(mh/4));77 x = getRandom(3+Math.floor(mw/3)*i,Math.floor(mw/3)*i + Math.floor((mw/3 - w)/2));78 y = getRandom(3+Math.floor(mh/3)*j,Math.floor(mh/3)*j +Math.floor((mh/3 - h)/2));79 for(k=x; k<x+w; k++){80 for(l=y; l<y+h; l++)81 this.setMustCarve(k,l);82 //this.setOpen(x,y);83 }84 }85 }86 }87 this.carveCell(Math.floor(mw/2), Math.floor(mh/2),"n");88 89 for(i=0; i<mw; i++){90 for(j=0; j<mh-1; j++){91 if (this.isSolid(i,j) && this.isOpen(i,j+1)){92 this.getCell(i,j)._wall = true;93 }94 }95 }96 }97 drawMap() {98 for (var i = 0; i < mw-1; i++) {99 for (var j = 0; j < mh-1; j++) {100 this.drawCellImage(i,j);101 this.getCell(i,j).draw();102 }103 }104 }105 carveCell(x,y,d) {106 // if the cell is already carved it should not be carved again107 if(this.isOpen(x,y) || this.getCell(x,y)._noCarve ) return false;108 109 // if the cell was a must carve cell it is always carved110 if(!this.mustCarve(x,y))111 {112 if (deadEndPC > Math.random()) return false;113 // if the cell is not must carve then we check the two diagonal neighbours in the direction of the carve114 // if they are both open carve. this prevents diagonal corners115 if(d=="n")116 {117 if( this.isOpen(x-1,y-1) || this.isOpen(x+1,y-1) ) return false;118 if( (this.isOpen(x-1,y) || this.isOpen(x+1,y) || this.isOpen(x,y-1) ) && (Math.random() > joinPC)) return false; 119 if( (this.isOpen(x-2,y) || this.isOpen(x+2,y) ) && (Math.random() < sideAvoidPC)) return false;120 if( (this.isOpen(x,y-2) || this.isOpen(x,y-3) ) && (Math.random() < forwardAvoidPC)) return false; 121 }122 if(d=="s")123 {124 if( this.isOpen(x-1,y+1) || this.isOpen(x+1,y+1)) return false;125 if( (this.isOpen(x-1,y) || this.isOpen(x+1,y) || this.isOpen(x,y+1) ) && (Math.random() > joinPC)) return false; 126 if( (this.isOpen(x-2,y) || this.isOpen(x+2,y) ) && (Math.random() < sideAvoidPC)) return false; 127 if( (this.isOpen(x,y+2) || this.isOpen(x,y+3) ) && (Math.random() < forwardAvoidPC)) return false; 128 }129 if(d=="e")130 {131 if(this.isOpen(x+1,y-1) || this.isOpen(x+1,y+1) ) return false;132 if( (this.isOpen(x,y+1) || this.isOpen(x,y-1) || this.isOpen(x+1,y) ) && (Math.random() > joinPC)) return false;133 if( (this.isOpen(x,y+2) || this.isOpen(x,y-2) || this.isOpen(x+2,y) ) && (Math.random() < sideAvoidPC)) return false;134 if( (this.isOpen(x+2,y) || this.isOpen(x+3,y) ) && (Math.random() < forwardAvoidPC)) return false; 135 136 }137 if(d=="w")138 {139 if(this.isOpen(x-1,y-1) || this.isOpen(x-1,y+1)) return false;140 if( (this.isOpen(x,y+1) || this.isOpen(x,y-1) || this.isOpen(x-1,y) ) && (Math.random() > joinPC)) return false;141 if( (this.isOpen(x,y+2) || this.isOpen(x,y-2) || this.isOpen(x-2,y) ) && (Math.random() < sideAvoidPC)) return false;142 if( (this.isOpen(x-2,y) || this.isOpen(x-3,y) ) && (Math.random() < forwardAvoidPC)) return false; 143 144 145 }146 }147 148 // if we have not returned we should carve the cell149 this.setOpen(x,y);150 if(deadSidesPC > Math.random()){151 switch(d){152 case "n", "s" : this.setNoCarve(x-1,y); this.setNoCarve(x+1,y); this.setNoCarve(x-2,y); this.setNoCarve(x+2,y)153 break;154 case "e", "w" : this.setNoCarve(x,y+1); this.setNoCarve(x,y-1); this.setNoCarve(x,y+2); this.setNoCarve(x,y-2);155 break;156 }157 }158 let success= false;159 // recursively carve the next cell160 while(d != "x"){161 if ((Math.random() > constDir)) d = ".";162 163 d = this.getCell(x,y).getDirection(d);164 //console.log(d);165 switch(d){166 case "n" : if (this.carveCell(x,y-1,d)) success =true;167 break;168 case "s" : if (this.carveCell(x,y+1,d)) success = true;169 break;170 case "e" : if (this.carveCell(x+1,y,d)) success = true;171 break;172 case "w" : if(this.carveCell(x-1,y,d)) success = true;173 break;174 175 case "x" : 176 break;177 default: console.log("carve error "); console.log(d); d="x"; 178 break;179 }180 181 182 }183 if (!success && !this.mustCarve(x,y) )184 {185 // it was a one stick long dead end186 this.setSolid(x,y);187 this.setNoCarve(x,y);188 //console.log("r");189 }190 191 return true;192 }193 createRoom(x,y,h,w){194 let i,j;195 for(i = x; i<x+w; i ++){196 for( j = y; j<y+h; j++){197 this.setMustCarve(i,j);198 }199 }200 }201 drawCellImage(x,y)202 {203 let cell = this.getCell(x,y);204 if (cell._isDrawn) return;205 let c = document.createElement("canvas");206 c.width = cs;207 c.height = cs;208 let ctx = c.getContext("2d");209 210 211 if (cell._solid)212 {213 ctx.fillStyle = colSolid;214 ctx.fillRect(0,0, cs, cs);215 // check if it a wall by looking at the one below to see if it is open216 217 if(cell._wall)218 {219 ctx.fillStyle = colWall;220 ctx.fillRect(0,cs/2, cs, cs/2); 221 ctx.strokeStyle = colVeryDarkSolid;222 ctx.beginPath();223 ctx.moveTo(0,cs)224 ctx.lineTo(cs,cs)225 ctx.stroke();226 ctx.fillStyle = colDarkSolid;227 ctx.fillRect(0,3*cs/8,cs, cs/8); 228 // check to see if it needs half length sides229 if(!this.getCell(x-1,y)._solid)230 {231 ctx.fillStyle = colDarkSolid;232 ctx.fillRect(0,0,cs/8, cs/2); 233 }234 if(!this.getCell(x+1,y)._solid)235 {236 ctx.fillStyle = colDarkSolid;237 ctx.fillRect(7*cs/8,0,cs/8, cs/2); 238 } 239 }240 else241 // check to see if it needs sidings on either side because they are open242 {243 if(!this.getCell(x-1,y)._solid && x>0)244 {245 ctx.fillStyle = colDarkSolid;246 ctx.fillRect(0,0,cs/8, cs); 247 }248 if(!this.getCell(x+1,y)._solid)249 {250 ctx.fillStyle = colDarkSolid;251 ctx.fillRect(7*cs/8,0,cs/8, cs); 252 }253 if(this.getCell(x-1,y)._wall )254 {255 ctx.fillStyle = colDarkSolid;256 ctx.fillRect(0,3*cs/8,cs/8, 5 * cs/4); 257 }258 if(this.getCell(x+1,y)._wall )259 {260 ctx.fillStyle = colDarkSolid;261 ctx.fillRect(7*cs/8,3*cs/8,cs/8, 5*cs/8); 262 } 263 }264 }265 else266 {267 268 //an open tile269 if(cell._mustCarve)270 {271 // its a room272 ctx.fillStyle = colOpenMed;273 ctx.fillRect(0,0, cs, cs);274 ctx.beginPath();275 ctx.moveTo(cs/8,cs/8);276 ctx.lineTo(7*cs/8,cs/8);277 ctx.lineTo(7*cs/8,7*cs/8)278 ctx.strokeStyle = colOpenLight;279 ctx.stroke();280 ctx.beginPath();281 ctx.moveTo(7*cs/8,7*cs/8)282 ctx.lineTo(cs/8,7*cs/8);283 ctx.lineTo(cs/8,cs/8)284 ctx.strokeStyle = colOpenDark;285 ctx.stroke();286 }287 else288 {289 ctx.fillStyle = colOpenMed;290 ctx.fillRect(0,0, cs, cs);291 ctx.fillStyle = colOpenMed;292 let r;293 for (let ii=0; ii<cs;ii+=cs/8){ for(let jj=0; jj<cs; jj+=cs/8){294 r = Math.random()295 if( r<0.33 ) {296 ctx.fillStyle = colOpenGrav;297 ctx.fillRect(ii,jj,cs/8,cs/8);298 }299 else if(r<.66){300 ctx.fillStyle = colOpenLight;301 ctx.fillRect(ii,jj,cs/8,cs/8);302 }303 }}304 ctx.fillStyle = colOpenMed;305 //ctx.fillRect(0,0, cs, cs);306 //ctx.lineWidth = 2;307 ctx.beginPath();308 ctx.moveTo(cs/8,cs/8);309 ctx.lineTo(7*cs/8,cs/8);310 ctx.lineTo(7*cs/8,7*cs/8)311 ctx.strokeStyle = colOpenLight;312 ctx.stroke();313 ctx.beginPath();314 ctx.moveTo(7*cs/8,7*cs/8)315 ctx.lineTo(cs/8,7*cs/8);316 ctx.lineTo(cs/8,cs/8)317 ctx.strokeStyle = colOpenDark;318 ctx.stroke();319 }320 321 // check to see if we have a solid below us that overhangs322 if(this.getCell(x,y+1)._solid )323 {324 ctx.fillStyle = colDarkSolid;325 ctx.fillRect(0,7*cs/8,cs,cs/8); 326 }327 }328 329 330 cell._imgSrc = ctx.getImageData(0,0,cs,cs);331 }332}333// resize334window.addEventListener("resize", resizeCanvasOrigin);335// grid helper functions336function resizeCanvasOrigin(){337 setCanvasOrigin(char._x,char._y);338 //console.log("inner,outer",window.innerWidth, window.outerWidth);339}340function setCanvasOrigin(x,y){341 //console.log(x,x*cs,window.innerWidth/2);342 // chrome version343 let xo = -x * cs + window.innerWidth/2 - 0.5*cs; // cs/2 is so that the origin of the chacter is aligned to the cell344 // explorer version - scroll bar is driving the difference345 //let xo = -x * cs + window.innerWidth/2 - cs; // cs/2 is so that the origin of the chacter is aligned to the cell346 let yo = -y * cs + window.innerHeight/2 - 0.5*cs ;347 document.getElementById("grid").style.left = xo+"px";348 document.getElementById("grid").style.top = yo+"px";349 350 tctx.putImageData(ctx.getImageData(x*cs,y*cs,cs,cs),0,0);351 tim.src = tc.toDataURL();352 353 tim.onload = function(){drawscalledimage()}354 355 //console.log(xo,yo); 356}357function drawscalledimage()358{359 hlctx.drawImage( tim , 0,0);360}361// function moveGrid(x0,y0,x1,y1,time,steps, bounce){ //time in ms362// let dx = (x1 - x0)/steps;363// let dy = (y1 - y0)/steps;364// if (bounce) {dx /= 2; dy /=2; }365// let ts = time/steps;366// moving = true;367// let stepCount=0;368 369// //var elem = document.getElementById("grid");370// var id = setInterval(frame,time/steps);371// function frame() {372// stepCount++;373// if (stepCount>steps) {374// clearInterval(id);375// moving=false;376// setCanvasOrigin(x1,y1)377// } else {378// x0+=dx;379// y0+=dy;380// setCanvasOrigin(x0,y0)381// // now lets move the monsters382// for(let i=mons.length-1;i>=0; i--){383// if(mons[i]._moving) mons[i].redrawObjBackground();384// } 385// for(let i=0; i< mons.length; i++){386// mons[i].move(stepCount);387// } 388// }389 390// }391 ...

Full Screen

Full Screen

SyncModel.js

Source:SyncModel.js Github

copy

Full Screen

1// this model is used to extend the user's own model.2// it adds the replication state.3Ext.data.SyncModel= {4 5 STATE: '_state',6 TOMBSTONE: '_ts',7 OID: '_oid',8 REF: '_ref',9 MODEL: '_model',10 11 state: undefined,12 13 createReplStorageModel: function(modelName) { // create the storage model, based on the user model14 var augmented_fields= this.fields.items.slice(0);15 augmented_fields= augmented_fields.concat([16 {name: '_state'},17 {name: '_ts'},18 {name: '_oid'},19 {name: '_ref'},20 {name: '_model'}21 ]);22 // JCM could the local storage proxy be added to the storage model...?23 var StorageModel= Ext.regModel("Sencha.StorageModel."+modelName, {24 fields: augmented_fields,25 idProperty: Ext.data.SyncModel.OID26 });27 28 return StorageModel;29 },30 oid: function() {31 return this.data[Ext.data.SyncModel.OID];32 },33 ref: function() {34 return this.data[Ext.data.SyncModel.REF];35 },36 37 userData: function() {38 var r= {};39 for(var i in this.data) {40 if (i[0]!=="_") {41 r[i]= this.data[i];42 }43 }44 return r;45 },46 47 isSystemModel: function() {48 var model_name= this.data[Ext.data.SyncModel.MODEL];49 return model_name!==undefined && model_name.indexOf("Ext.data.",0)===0;50 },51 changeReplicaNumber: function(old_replica_number,new_replica_number) {52 this.setup();53 var changed= false;54 this.forEachCS(this.state,function(cs) {55 var t= cs.changeReplicaNumber(old_replica_number,new_replica_number)56 changed= changed || t;57 return cs;58 },this);59 var v= this.oid();60 if (v) {61 var id_cs= new Ext.data.CS(v);62 if (id_cs.changeReplicaNumber(old_replica_number,new_replica_number)) {63 this.data[Ext.data.SyncModel.OID]= id_cs.to_s();64 changed= true;65 }66 }67 return changed;68 },69 setCreateState: function(generator) {70 this.state= {};71 var cs= generator();72 this.setPair(Ext.data.SyncModel.OID,cs.to_s(),cs);73 this.forEachValue(this.data,[],function(path,value) {74 if (path[0]!==Ext.data.SyncModel.OID) {75 this.setCS(path,generator());76 }77 },this);78 },79 80 setUpdateState: function(generator) {81 var changes= this.getChanges();82 for (name in changes) {83 if (name!==Ext.data.SyncModel.STATE && name!==Ext.data.SyncModel.OID) {84 this.setUpdateStateValue([name],this.modified[name],changes[name],generator);85 }86 }87 },88 89 setUpdateStateValue: function(path,before_value,after_value,generator) {90 //console.log('setUpdateStateValue',path,before_value,after_value)91 if (this.isComplexValueType(after_value)) {92 if (before_value) {93 var added= {};94 if (this.isComplexValueType(before_value)) {95 if (this.valueType(before_value)===this.valueType(after_value)) {96 added= Ext.data.utilities.minus(after_value,before_value);97 var changed= Ext.data.utilities.intersection(after_value,before_value);98 for(var name2 in changed) {99 if (changed.hasOwnProperty(name2)) { 100 if (before_value[name2]!==after_value[name2]) {101 added[name2]= after_value[name2]102 }103 }104 }105 } else {106 added= after_value;107 this.setCS(path,generator()); // value had a different type before, a complex type108 }109 } else {110 added= after_value;111 this.setCS(path,generator()); // value had a different type before, a primitive type112 }113 } else {114 added= after_value;115 this.setCS(path,generator()); // value didn't exist before116 }117 for(var name2 in added) {118 if (added.hasOwnProperty(name2)) {119 var next_before_value= before_value ? before_value[name2] : undefined;120 this.setUpdateStateValue(path.concat(name2),next_before_value,after_value[name2],generator);121 }122 }123 } else {124 this.setCS(path,generator()); // value has a primitive type125 }126 },127 setDestroyState: function(generator) {128 var cs= generator();129 this.data[Ext.data.SyncModel.TOMBSTONE]= cs.to_s();130 this.setCS(Ext.data.SyncModel.TOMBSTONE,cs);131 },132 isNotDestroyed: function() { // test if a record has been deleted133 var t= this.data[Ext.data.SyncModel.TOMBSTONE]134 return (t===undefined || t==='');135 },136 137 getUpdates: function(csv) {138 //console.log('updates',Ext.encode(csv))139 this.setup();140 var updates= [];141 var oid= this.oid();142 this.forEachPair(this.data,this.state,[],[],function(path,values,cs){143 if (cs) {144 var cs2= csv.get(cs);145 if (!cs2 || cs2.lessThan(cs)) {146 updates.push({147 i: oid,148 p: path.length==1 ? path[0] : path, 149 v: values.length==1 ? values[0] : values, 150 c: cs151 });152 }153 }154 },this);155 //console.log('updates =>',Ext.encode(updates))156 return updates;157 },158 159 putUpdate: function(update) {160 //console.log('applyUpdate',update)161 return this.setPair(update.p,update.v,update.c);162 },163 164 equals: function(r) {165 this.forEachPair(this.data,this.state,[],[],function(path,values,cs) {166 var p= r.getPair(path);167 var value= values[values.length-1];168 if (!(cs.equals(r.c) && value===r.v)) {169 return false;170 }171 },this);172 return true;173 },174 forEachPair: function(data,state,path,values,callback,scope) {175 //console.log('forEachPair',Ext.encode(data),Ext.encode(state),Ext.encode(path),Ext.encode(values));176 this.setup();177 for(var name in state) {178 if (state.hasOwnProperty(name)) {179 var new_state= state[name];180 var new_data= data[name];181 var new_path= path.concat(name);182 var new_data_type= this.valueType(new_data);183 var new_value;184 switch (new_data_type) {185 case 'object':186 new_value= {};187 break;188 case 'array':189 new_value= [[]];190 break;191 default:192 new_value= new_data;193 }194 var new_values= values.concat(new_value);195 switch (this.valueType(new_state)) {196 case 'string':197 callback.call(scope,new_path,new_values,new Ext.data.CS(new_state));198 break;199 case 'array':200 switch (new_data_type) {201 case 'undefined':202 console.log('Warning - There was no data for the state at path',new_path);203 console.log('Warning -',Ext.encode(this.data));204 break;205 case 'object':206 case 'array':207 callback.call(scope,new_path,new_values,new Ext.data.CS(new_state[0])); // [cs,state]208 this.forEachPair(new_data,new_state[1],new_path,new_values,callback,scope); // [cs,state]209 break;210 default:211 callback.call(scope,new_path,new_values,new Ext.data.CS(new_state[0])); // [cs,state]212 break;213 }214 break;215 }216 }217 }218 }, 219 220 forEachValue: function(data,path,callback,scope) {221 var n, v;222 for(n in data) {223 if (data.hasOwnProperty(n)) {224 v= data[n];225 if (v!==this.state) {226 var path2= path.concat(n);227 callback.call(scope,path2,v);228 if (this.isComplexValueType(v)) {229 this.forEachValue(v,path2,callback,scope);230 }231 }232 }233 }234 },235 getCSV: function() {236 var csv= new Ext.data.CSV();237 this.forEachCS(this.state,function(cs) {238 csv.add(cs);239 },this);240 return csv;241 },242 forEachCS: function(state,callback,scope) {243 for(name in state) {244 if (state.hasOwnProperty(name)) {245 var next_state= state[name];246 switch (this.valueType(next_state)) {247 case 'string':248 var cs= callback.call(scope,new Ext.data.CS(next_state));249 if (cs) { state[name]= cs.to_s(); }250 break;251 case 'array':252 var cs= callback.call(scope,new Ext.data.CS(next_state[0]));253 if (cs) { state[name][0]= cs.to_s(); } // [cs,state]254 this.forEachCS(next_state[1],callback,scope); // [cs,state]255 break;256 }257 }258 }259 },260 getCS: function(path) {261 this.setup();262 var state= this.state;263 if (Ext.isArray(path)) {264 var l= path.length;265 var e= l-1;266 for(var i=0;i<l;i++) {267 var name= path[i];268 if (i===e) {269 return this.do_getCS(state,name);270 } else {271 state= this.do_getState(state,name);272 }273 }274 } else {275 return this.do_getCS(state,path);276 }277 },278 279 do_getCS: function(state,name) {280 var cs= undefined;281 var state= state[name];282 if (state) {283 switch (this.valueType(state)) {284 case 'string':285 cs= new Ext.data.CS(state);286 break;287 case 'array':288 cs= new Ext.data.CS(state[0]); // [cs,state]289 break;290 default:291 console.log("Error - SyncModel - do_getCS - unexpected type in state for",name,":",typeof state,state);292 console.log('state',Ext.encode(this.data));293 cs= new Ext.data.CS();294 break;295 }296 } // else undefined297 return cs;298 },299 setCS: function(path,cs) {300 //console.log('setCS',Ext.isArray(path) ? path.join() : path,cs.to_s())301 this.setup();302 var state= this.state;303 if (Ext.isArray(path)) {304 var l= path.length;305 var e= l-1;306 for(var i=0;i<l;i++) {307 var name= path[i];308 if (i===e) {309 this.do_setCS(state,name,cs);310 } else {311 state= this.do_getState(state,name);312 }313 }314 } else {315 this.do_setCS(state,path,cs);316 }317 },318 319 do_setCS: function(state,name,cs) {320 var cs_s= (cs instanceof Ext.data.CS) ? cs.to_s() : cs;321 var state2= state[name];322 if (state2) {323 switch (this.valueType(state2)) {324 case 'string':325 state[name]= cs_s;326 break;327 case 'array':328 state2[0]= cs_s; // [cs,state]329 break;330 default:331 console.log("Error - SyncModel - do_setCS - unexpected type in state for",name,":",typeof state2,state2);332 console.log('state',Ext.encode(state));333 console.log('name',name,'cs',cs_s);334 state[name]= cs_s;335 }336 } else {337 state[name]= cs_s;338 }339 //console.log('do_setCS',name,cs_s,Ext.encode(state))340 },341 getPair: function(path) {342 this.setup();343 var data= this.data;344 var state= this.state;345 if (Ext.isArray(path)) {346 var l= path.length;347 var e= l-1;348 for(var i=0;i<l;i++) {349 var name= path[i];350 if (i===e) {351 return {352 v: data ? data[name] : data,353 c: this.do_getCS(state,name)354 };355 } else {356 state= this.do_getState(state,name);357 data= data ? data[name] : data;358 }359 }360 } else {361 return {362 v: data[path],363 c: this.do_getCS(state,path)364 };365 }366 },367 368 setPair: function(path,values,new_cs) {369 //console.log('setPair',Ext.encode(path),Ext.encode(values),Ext.encode(new_cs));370 //console.log('setPair',Ext.encode(this.data));371 var changed= false;372 this.setup();373 if (!Ext.isArray(path)) {374 path= [path];375 values= [values];376 }377 var data= this.data;378 var state= this.state;379 var l= path.length;380 var e= l-1;381 for(var i=0;i<l;i++) {382 var name= path[i];383 var new_value= values[i]; 384 var old_cs= this.do_getCS(state,name);385 var old_value= data[name];386 var old_value_type= this.valueType(old_value);387 var new_value_type= this.valueType(new_value);388 var sameComplexType= 389 ((old_value_type==='object' && new_value_type==='object') ||390 (old_value_type==='array' && new_value_type==='array'));391 if (old_cs) {392 if (new_cs.greaterThan(old_cs)) {393 if (sameComplexType) {394 new_value= undefined; // re-assert, don't overwrite395 }396 // new_cs is gt old_cs, so accept update397 if (this.do_setPair(data,state,name,new_value,new_cs)) {398 changed= true;399 }400 } else {401 // new_cs is not gt old_cs402 if (sameComplexType) {403 // but this value type along the path is the same, so keep going... 404 } else {405 // and this type along the path is not the same, so reject the update.406 return changed;407 }408 }409 } else {410 // no old_cs, so accept update411 if (this.do_setPair(data,state,name,new_value,new_cs)) {412 changed= true;413 }414 }415 if (i!==e) {416 data= this.do_getData(data,name);417 state= this.do_getState(state,name,new_cs);418 }419 }420 //console.log('setPair => ',Ext.encode(this.data));421 return changed;422 },423 424 do_getState: function(state,name,cs) {425 var next_state= state[name];426 switch (this.valueType(next_state)) {427 case 'undefined':428 var new_state= {};429 state[name]= [cs,new_state];430 state= new_state;431 break;432 case 'string':433 var new_state= {};434 state[name]= [next_state,new_state];435 state= new_state;436 break;437 case 'array':438 state= next_state[1];439 break;440 default:441 throw "Error - SyncModel - do_getState - unexpected type in state: "+(typeof next_state)+" "+next_state442 }443 return state;444 },445 446 do_setPair: function(data,state,name,new_value,new_cs) {447 var changed= false;448 if (new_value!==undefined) {449 this.do_setData(data,name,new_value)450 changed= true;451 }452 if (new_cs!==undefined) { 453 this.do_setCS(state,name,new_cs);454 changed= true;455 }456 return changed;457 },458 459 do_getData: function(data,name) {460 return data[name];461 },462 do_setData: function(data,name,value) {463 //console.log(Ext.encode(data),"[",name,"]=",Ext.encode(value));464 data[name]= value;465 },466 467 valueType: function(value) { // returns undefined, number, boolean, string, object, array468 var t= typeof value;469 if (t==='object' && (value instanceof Array)) {470 t= 'array';471 }472 return t;473 },474 475 valueEquals: function(v1,v2) {476 var r= false;477 var t1= this.valueType(v1);478 var t2= this.valueType(v2);479 if (t1===t2) {480 switch (t1) {481 case 'object':482 case 'array':483 r= Ext.encode(v1)===Ext.encode(v2); // JCM I'm sure there's a better way to do this...484 break;485 default:486 r= v1===v2;487 }488 }489 return r;490 },491 492 isComplexValueType: function(value) { // return true for an object or an array493 return (typeof value==='object');494 },495 496 setup: function() {497 this.data[Ext.data.SyncModel.STATE]= this.data[Ext.data.SyncModel.STATE] || {};498 this.state= this.data[Ext.data.SyncModel.STATE];499 }500 ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2 if (err) {3 return console.error(err);4 }5 wpt.getTestStatus(data.data.testId, function(err, data) {6 if (err) {7 return console.error(err);8 }9 console.log(data);10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = wptools.page('Albert Einstein');3wiki.get(function(err, resp) {4 if (!err) {5 console.log(resp);6 }7});8var wptools = require('wptools');9var wiki = wptools.page('Albert Einstein');10wiki.get(function(err, resp) {11 if (!err) {12 console.log(resp);13 }14});15var wptools = require('wptools');16var wiki = wptools.page('Albert Einstein');17wiki.get(function(err, resp) {18 if (!err) {19 console.log(resp);20 }21});22var wptools = require('wptools');23var wiki = wptools.page('Albert Einstein');24wiki.get(function(err, resp) {25 if (!err) {26 console.log(resp);27 }28});29var wptools = require('wptools');30var wiki = wptools.page('Albert Einstein');31wiki.get(function(err, resp) {32 if (!err) {33 console.log(resp);34 }35});36var wptools = require('wptools');37var wiki = wptools.page('Albert Einstein');38wiki.get(function(err, resp) {39 if (!err) {40 console.log(resp);41 }42});43var wptools = require('wptools');44var wiki = wptools.page('Albert Einstein');45wiki.get(function(err, resp) {46 if (!err) {47 console.log(resp);48 }49});50var wptools = require('wptools');51var wiki = wptools.page('Albert Einstein');52wiki.get(function(err, resp) {53 if (!err) {54 console.log(resp);55 }56});57var wptools = require('wpt

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var cs = wptoolkit.cs;3var cs = require('wptoolkit').cs;4var wptoolkit = require('wptoolkit');5var cs = wptoolkit.cs;6var cs = require('wptoolkit').cs;7var cs = require('wptoolkit').cs;8var cs = require('wptoolkit').cs;9var cs = require('wptoolkit').cs;10var cs = require('wptoolkit').cs;11var cs = require('wptoolkit').cs;12var cs = require('wptoolkit').cs;13var cs = require('wptoolkit').cs;14var cs = require('wptoolkit').cs;15var wptoolkit = require('wptoolkit');16var cs = wptoolkit.cs;17var cs = require('wptoolkit').cs;18var cs = require('wptoolkit').cs;19var wptoolkit = require('wptoolkit');20var cs = wptoolkit.cs;21var cs = require('wptoolkit').cs;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org', 'A.8d0b7c9e9b1f1f4f8d4e4b4e4c4b4e4');3 if (err) return console.error(err);4 console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org', 'A.8d0b7c9e9b1f1f4f8d4e4b4e4c4b4e4');8 if (err) return console.error(err);9 console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org', 'A.8d0b7c9e9b1f1f4f8d4e4b4e4c4b4e4');13 if (err) return console.error(err);14 console.log(data);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org', 'A.8d0b7c9e9b1f1f4f8d4e4b4e4c4b

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 wpt 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