How to use optionsPath method in stryker-parent

Best JavaScript code snippet using stryker-parent

Constraints.js

Source:Constraints.js Github

copy

Full Screen

1/**2 * Constraints.js is used to traverse option constraint objects recurcivly to provide both input and validation of input3 * input received from a constraint object creates an identical object with the input values where the constraints were.4 *5 * the simplest option constraint object looks like this:6 * {7 * optionName : constraint8 * }9 * more complex nested:10 * {11 * name : {12 * name2 : constraint,13 * name3 : {14 * name4 : constraint15 * }16 * }17 *}18 *19 * optionName : can be any name you desire and will be displayed to the user as the input Label20 * Special treatment is given for the following name types:21 * optionName like on[A-Z]* are event properties and they are given a textarea within which to define the event stuff22 *23 * constraint : takes on many forms:24 * [num,num,num] = Min, Max, Default Number. Input must fall inclusive between min and max and be a numeric value25 * [string,num,num[,string]] = regex must be quoted to make it a string since JSON.encode/decode does not do native regex eg "/regex/". Min Length, Max Length, Default Value.26 * [string[,string]] = Select one from the list (first one is default)27 * [true/false] = Checkbox yes/no,28 * number = Must be numeric, but is unconstrained (number specified is default number)29 * string = Must be string, but is unconstrained (string specified is default string)30 * object = Traverse into this object for more constraints31 */32if (!RPG) var RPG = {};33if (!RPG.Constraints) RPG.Constraints = {};34if (typeof exports != 'undefined') {35 Object.merge(RPG,require('./Random.js'));36 Object.merge(RPG,require('../server/Log/Log.njs'));37 var logger = RPG.Log.getLogger('RPG.Constraints');38 module.exports = RPG;39}40Object.extend({41 /**42 * Object.pathToObject43 * Accepts a string or array path.44 * source is optional if you want to append to existing object45 *46 * returns new nested object from the path47 * example:48 * path = ['p1','p2','p3'] or49 * path = 'p1.p2.p3'50 *51 * root = p1: {52 * p2: {53 * p3 : child = {}54 * }55 * }56 *57 * return {58 * root : p159 * child : p360 * }61 */62 pathToObject : function(source,path) {63 if (typeOf(path) == 'string') path = path.split('.');64 var child = source || {};65 var root = child;66 path.each(function(p){67 if (!child[p]) child[p] = {};68 child = child[p];69 });70 return {71 root : root,72 child : child73 };74 },75 /**76 * @tod UNTESTED... probably dons't work77 *78 * Recursivly traverse an object and call the 'leafFunc' function at each leaf and the 'branchFunc' at each branch79 *80 * branch/leaf Func arg object81 * {82 * path : array eg: ['terrain','grass']83 * key : string. leaf/branch key. eg 'grass'84 * content : contents of branc/leaf85 * }86 *87 */88 recurse : function(source,leafFunc,branchFunc,internal) {89 if (!internal) internal = {};90 if (!internal.path) internal.path = [];91 if (internal.key) {92 internal.path.push(internal.key);93 }94 internal.content = source;95 if (typeOf(source) != 'object') {96 internal.returns = leafFunc(internal);97 } else {98 branchFunc(internal);99 Object.each(source,function(content,key){100 internal.key = key;101 internal.content = content;102 internal.returns = Object.recurse(content,leafFunc,internal);103 });104 }105 internal.path.pop();106 return internal.returns;107 },108 diff : function(original,updated,diff,path,usingUpdated) {109 if (!diff) diff = {};110 if (!path) path = [];111 //check incoming 'original', if it is an object we can iterate through it.112 if (typeOf(original) == 'object' && !usingUpdated) {113 Object.each(original,function(v,k){114 path.push(k);115 var u = Object.getFromPath(updated,path);116 if (!u) {117 path.pop();118 return;119 }120 //determine the type of the object value121 switch (typeOf(v)) {122 //recurse into objects123 case 'object' :124 //push the object's key onto the path125 Object.diff(v,updated,diff,path);126 break;127 case 'array' :128 case 'function' :129 if (u && v && v.toString() != u.toString()) {130 path.pop();131 Object.pathToObject(diff,path).child[k] = u;132 path.push(k);133 }134 break;135 //default (number/string/boolean)136 default :137 if (v != u) {138 path.pop();139 Object.pathToObject(diff,path).child[k] = u;140 path.push(k);141 }142 }143 path.pop();144 });145 }146 return diff;147 }148});149Array.extend({150 prejoin : function(source,str,join){151 if (!source) return '';152 var ret = '';153 source.each(function(value,index){154 ret += str + value;155 if (join && index<source.length-1) {156 ret += join;157 }158 });159 return ret;160 }161});162/**163 * Returns a Div Element Tabbed Input Form for a option constraints object164 *165 * Recursivly traverses an option constrain object an generates tabs for the first level of constraints, the nested tables for all sub level constraints166 */167RPG.Constraints.getTabs = function(content,key,optPath,loadOptions,id) {168 var tabs = new Jx.TabBox({169 scroll : false170 });171 Object.each(content,function(opt,key) {172 tabs.add(new Jx.Tab({173 label: key.capitalize(),174 content: RPG.Constraints.getTable(opt,key,[],loadOptions,id)175 }));176 }.bind(this));177 return tabs.toElement();178}179/**180 * Recursivly traverses an option constrain object and generates nested tables for all constraints181 *182 * constraint_options : a constrain options object183 * optionsName : appended to create the optionsPath (can be null to start. used primarily by the recursion)184 * optionsPath : array or null. gets filled/emptied with the optionsName to get track of the depth185 * loadOptions : a filled out options object or null,186 * id : added to the className to uniquely identify this whole set of options187 *188 */189RPG.Constraints.getTable = function(constraint_options,optionName,optionsPath,loadOptions,id) {190 if (!optionsPath || (optionsPath && typeOf(optionsPath) != 'array')) {191 optionsPath = [];192 }193 optionName && optionsPath.push(optionName);194 /**195 * Reached the depth of the config.196 * use the content of the config to197 */198 if (typeOf(constraint_options) != 'object') {199 var elm = null;200 var value = null;201 var className = 'mapEditorConfigInput configFor_'+id202 if (loadOptions) {203 value = Object.getFromPath(loadOptions,optionsPath);204 }205 var con0 = (typeOf(constraint_options) == 'array'?constraint_options[0]:constraint_options);206 var con1 = (typeOf(constraint_options) == 'array' && constraint_options[1]) || null;207 var con2 = (typeOf(constraint_options) == 'array' && constraint_options[2]) || null;208 var con3 = (typeOf(constraint_options) == 'array' && constraint_options[3]) || null;209 var type0 = (typeOf(constraint_options) == 'array' && typeOf(con0)) || null;210 var type1 = (typeOf(constraint_options) == 'array' && typeOf(con1)) || null;211 var type2 = (typeOf(constraint_options) == 'array' && typeOf(con2)) || null;212 var path = Array.clone(optionsPath);213 switch (true) {214 /**215 * Array: [min,max,default]216 */217 case (Number.from(con0)!=null && Number.from(con1)!=null && constraint_options.length <= 3) :218 con2 = con2 || 0;219 elm = new Element('div').adopt(220 new Element('input',{221 type : 'text',222 id : path.join('__'),223 value : (value?value:''+con2),224 size : (value?value:''+con2).length > 3?(value?value:''+con2).length:3,225 title : '(Min:'+con0+' Max:'+con1+')',226 'class' : className + ' textRight'227 }),228 new Element('span',{229 html : '&nbsp;&nbsp;'230 }),231 new Jx.Button({232 label : 'Random',233 onClick : function(event) {234 $(path.join('__')).value = RPG.Random.random(con0 || 0,con1);235 }236 }).toElement()237 );238 break;239 /**240 * Array: [regex,min,max,default]241 */242 case (type0 == 'string' && Number.from(con1)!=null && Number.from(con2) !=null && constraint_options.length <= 4) :243 elm = new Element('div').adopt(244 new Element('input',{245 type : 'text',246 id : path.join('__'),247 value : (value?value:''+(con3 || '')),248 size : 10,249 title : '(Min:'+con1+' Max:'+con2+')',250 'class' : className251 }),252 new Element('span',{253 html : '&nbsp;&nbsp;'254 }),255 new Jx.Button({256 'class' : 'randomFor_'+id,257 label : 'Random',258 onClick : function(event) {259 $(path.join('__')).value = RPG.Generator.Name.generate({260 name : {261 seed : RPG.Random.seed,262 length : RPG.Random.random(con1,con2)263 }264 });265 }266 }).toElement()267 );268 break;269 /**270 * Array: [string[..]]271 */272 case (type0 == 'string') :273 var select = new Jx.Field.Select({274 id : path.join('__'),275 containerClass : 'configFor_' + id276 });277 constraint_options.each(function(opt){278 select.addOption({279 value :''+opt,280 text : ''+opt,281 selected : (value==opt?true:false)282 });283 });284 elm = new Element('div').adopt(285 select,286 new Element('span',{287 html : '&nbsp;&nbsp;'288 }),289 new Jx.Button({290 label : 'Random',291 onClick : function(event) {292 this.getParent().getElements('select')[0].value = Array.getSRandom(constraint_options);293 }294 }).toElement()295 );296 break;297 /**298 * Key like /^on[A-Z]/299 * matches events300 */301 case (/^on[A-Z]/.test(optionName)):302 elm = new Element('textarea',{303 cols : 30,304 rows : 3,305 id : path.join('__'),306 html : (value?value:constraint_options),307 'class' : className308 });309 break;310 /**311 * Boolean Values312 */313 case (constraint_options && (typeOf(constraint_options[0]) == 'boolean' || constraint_options === 'true' || constraint_options === 'false')) :314 elm = new Element('input',{315 type : 'checkbox',316 id : path.join('__'),317 checked : (value?value:typeOf(constraint_options)=='array'?constraint_options[0]:constraint_options),318 'class' : className319 });320 break;321 /**322 * text default323 */324 default:325 elm = new Element('input',{326 type : 'text',327 id : path.join('__'),328 value : (value?value:constraint_options),329 size : (typeOf(constraint_options) == 'number'?3:10),330 'class' : className331 });332 break;333 }334 optionName && optionsPath.pop();335 value = null;336 className = null;337 return elm; //Return the newly created element to be inserted into the table338 }339 var tbl = new HtmlTable({340 zebra : optionsPath.length%2 == 1,341 selectable : false,342 useKeyboard : false,343 properties : {344 cellpadding : 2345 }346 });347 var rows = [];348 Object.each(constraint_options,function(opt,k){349 rows.push([350 {351 properties : {352 'class' : 'vTop textRight NoWrap'353 },354 content : k.capitalize().hyphenate().split('-').join(' ').capitalize() +':'355 },356 {357 properties : {358 'class' : 'NoWrap'359 },360 content : RPG.Constraints.getTable(opt,k,optionsPath,loadOptions,id) //recursively load options361 }362 ]363 );364 });365 tbl.pushMany(rows);366 optionsPath.pop();//pop off the last path name from the optionpath367 return tbl.toElement(); //return the table of options368}369RPG.Constraints.getDisplayTable = function(options,optionName,optionsPath) {370 if (!optionsPath || (optionsPath && typeOf(optionsPath) != 'array')) {371 optionsPath = [];372 }373 optionName && optionsPath.push(optionName);374 /**375 * Reached the depth of the config.376 * use the content of the config to377 */378 if (typeOf(options) != 'object') {379 optionsPath.pop();380 return new Element('div',{381 html : options,382 'class' : 'textLarge textLeft'383 });384 }385 var tbl = new HtmlTable({386 zebra : false,387 selectable : false,388 useKeyboard : false,389 properties : {390 cellpadding : 2,391 'class' : 'constraint-table',392 styles : {393 'background-color' : 'rgb('+ ((optionsPath.length+1)*25)+','+ ((optionsPath.length+1)*25)+','+ ((optionsPath.length+1)*25)+')'394 }395 }396 });397 var rows = [];398 Object.each(options,function(opt,k){399 if (!['database','genOptions','generator','property'].contains(k) ) {400 rows.push([401 {402 properties : {403 'class' : 'vTop textRight NoWrap textSmall'404 },405 content : k.capitalize().hyphenate().split('-').join(' ').capitalize() +':'406 },407 {408 properties : {409 'class' : 'NoWrap'410 },411 content : RPG.Constraints.getDisplayTable(opt,k,optionsPath) //recursively load options412 }413 ]414 );415 }416 });417 tbl.pushMany(rows);418 optionsPath.pop();//pop off the last path name from the optionpath419 return tbl.toElement(); //return the table of options420}421/**422 * pID refers to the parent element ID that contains all config elements. can be null423 * id : the id as used in the RPG.Constraints.getTable424 *425 * returns populated options object426 */427RPG.Constraints.getFromInput = function(pID,id) {428 var options = {};429 $$((pID?'#'+pID:'')+' .configFor_'+id).each(function(elm){430 var opt = options;431 var p = elm.id.split('__');432 p.each(function(p) {433 if (!opt[p]) {434 opt[p] = {};435 }436 opt = opt[p];437 });438 var parentObj = Object.getFromPath(options,p.slice(0,p.length-1));439 var key = p.slice(-1)[0];440 switch (true) {441 case ['input'].contains(elm.nodeName.toLowerCase()) && elm.type.toLowerCase() == 'checkbox' :442 parentObj[key] = elm.checked;443 break444 case ['input','textarea'].contains(elm.nodeName.toLowerCase()):445 parentObj[key] = elm.value;446 break;447 case 'span' == elm.nodeName.toLowerCase() :448 parentObj[key] = $$('#'+elm.id+' select')[0].value449 break450 default:451 break;452 }453 key = null;454 parentObj = null;455 p = null;456 opt = null;457 });458 return options;459}460/**461 * random462 *463 * uses a option constraints object to generate a random options object464 * ex:465 * constraint_options : { optionName : [0,5,2] }466 * returns : { optionName : Random(0,5) }467 *468 */469RPG.Constraints.random = function(constraint_options,rand,options,path,key) {470 if (!options) options = {};471 if (!path) path = [];472 rand = rand || RPG.Random;473 if (typeOf(constraint_options) != 'object') {474 var content = constraint_options;475 var con0 = (typeOf(content) == 'array'?content[0]:content);476 var con1 = (typeOf(content) == 'array' && content[1]) || null;477 var con2 = (typeOf(content) == 'array' && content[2]) || null;478 var con3 = (typeOf(content) == 'array' && content[3]) || null;479 var type0 = (typeOf(content) == 'array' && typeOf(con0)) || null;480 var optName = path.pop();481 var opt = Object.pathToObject(options,path);482 path.push(key);483 switch (true) {484 /**485 * Array: [min,max,default]486 */487 case (Number.from(con0)!=null && Number.from(con1)!=null && content.length <= 3) :488 opt.child[optName] = rand.random(Number.from(con0),Number.from(con1));489 break;490 /**491 * Array: [regex,min,max,default]492 */493 case (type0 == 'string' && Number.from(con1)!=null && Number.from(con2) !=null && content.length <= 4) :494 var n = null;495 if (typeof exports != 'undefined') {496 n = require('./Game/Generators/Words.js').Generator.Name497 } else {498 n = RPG.Generator.Name;499 }500 opt.child[optName] = n.generate({501 name : {502 seed : rand.seed,503 length : rand.random(Number.from(con1),Number.from(con2))504 }505 });506 break;507 /**508 * Array: [string[..]]509 */510 case (type0 == 'string') :511 opt.child[optName] = Array.getSRandom(content,rand);512 break;513 /**514 * Key like /^on[A-Z]/515 * matches events516 */517 case (/^on[A-Z]/.test(key)):518 break;519 /**520 * Boolean Value521 */522 case (typeof content == 'array' && typeOf(content[0]) == 'boolean') || content === 'true' || content === 'false' :523 opt.child[optName] = rand.random() > 0.5?true:false;524 break;525 /**526 * default527 */528 default:529 break;530 }531 } else {532 Object.each(constraint_options,function(content,key) {533 path.push(key);534 RPG.Constraints.random(content,rand,options,path,key);535 path.pop();536 });537 }538 return options;539}540/**541 * Merge constraint options from the main object (eg: RPG.terrain, RPG.world, RPG.npc etc)542 * Path : eg ['terrain','dirt']543 * Constraints : nested constraints object544 *545 * exapmle:546 * terrain : {547 * options : {548 * name : [constraint1], <--- overridden by dirt's options.name549 * id : [constraint1] <---550 * },551 * dirt : {552 * options : {553 * name: [constraint2] <--- overrides parent options.name554 * }555 * }556 *557 * Returns: a recursivly merged object who contains all parent options while allowing child options to override parent options558 *559 * options : {560 * name : [constraint2],561 * id : [constraint1]562 * }563 */564RPG.Constraints.getConstraints = function(path, constraints) {565 var constraing_options = {};566 var cPath = [];567 constraing_options = Object.clone(constraints.options);568 path.each(function(p){569 cPath.push(p);570 var opts = Object.getFromPath(constraints,cPath);571 if (opts && opts.options) {572 Object.merge(constraing_options,opts.options);573 }574 opts = null;575 });576 cPath = null;577 return constraing_options;578}579/**580 * recursivly validate options against a options constraint object581 *582 * returns empty array if all is ok583 * or array of errors encountered.584 *585 */586RPG.Constraints.validate = function(options,option_constraints) {587 var errors = [];588 Object.each(options, function(content,key){589 RPG.Constraints._validateRecurse(content,key,option_constraints,[],errors);590 });591 return errors;592}593RPG.Constraints._validateRecurse = function(content,key,option_constraints,path,errors) {594 path.push(key);595 if (typeOf(content) == 'object') {596 Object.each(content, function(c,k){597 RPG.Constraints._validateRecurse(c,k,option_constraints,path,errors);598 });599 } else {600 var constraint = Object.getFromPath(option_constraints,path);601 var con0 = typeOf(constraint) == 'array' && constraint[0] || constraint;602 var con1 = typeOf(constraint) == 'array' && constraint[1] || null;603 var con2 = typeOf(constraint) == 'array' && constraint[2] || null;604 var type0 = typeOf(constraint) == 'array' && typeOf(con0) || null;605 switch (true) {606 /**607 * Array: numbers [min,max,default]608 */609 case (Number.from(con0) != null && Number.from(con1) != null && constraint.length <= 3) :610 if (Number.from(content) === null) {611 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid:<br>'+unescape(Object.toQueryString(Object.values(constraint).associate(['Min','Max','Default']))).replace(/\&/g,', ')+'<br>');612 } else {613 if (content === 0) {614 break;615 }616 content = Number.from(content);617 if (content < con0 || content > con1) {618 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid:<br>'+unescape(Object.toQueryString(Object.values(constraint).associate(['Min','Max','Default']))).replace(/\&/g,', ')+'<br>');619 }620 }621 break;622 /**623 * Array: [(string|regex),min,max[,default]]624 */625 case (type0 == 'string' && Number.from(con1) !=null && Number.from(con2) !=null && constraint.length <= 4) :626 if (content.length < Number.from(con1) || content.length > Number.from(con2) || (/^\//.test(con0) && !new RegExp(con0.substr(1,con0.length-2)).test(content))) {627 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid:<br>'+unescape(Object.toQueryString(Object.values(constraint).associate(['Allowed','Min','Max']))).replace(/\&/g,', ')+'<br>');628 }629 break;630 /**631 * Array of strings: [type0=string[,type1=string,...]]632 */633 case (type0 == 'string' && con1 == 'string') :634 if (!content || !constraint.contains(content)) {635 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid:<br>Must be one of: '+JSON.encode(constraint)+'<br>');636 }637 break;638 /**639 * Key like /^on[A-Z]/640 * matches events641 */642 case typeOf(constraint) == 'string' && /^on[A-Z]/.test(key):643 if (typeOf(content) != 'string') {644 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid:<br>Must be a string.'+'<br>');645 }646 break;647 /**648 * Boolean Values649 */650 case (typeOf(constraint) == 'array' && typeOf(constraint[0]) == 'boolean') || constraint === 'true' || constraint === 'false' :651 if (typeOf(content) != 'boolean') {652 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid:<br>Must be <b>true</b> or <b>false</b>.'+'<br>');653 }654 break;655 /**656 * String Values657 */658 case typeOf(constraint) == 'string' :659 if (typeOf(content) != 'string') {660 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid:<br>Must be a string.'+'<br>');661 }662 break;663 /**664 * array Values665 */666 case typeOf(constraint) == 'array' :667 if (typeOf(content) != 'string') {668 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid ('+constraint+'):<br>Must be a string.'+'<br>');669 }670 break;671 /**672 * array Values673 */674 case typeOf(constraint) == 'number' :675 if (typeOf(content) != 'number') {676 content = Number.from(content);677 }678 if (content === 0) {679 break;680 }681 if (!content) {682 errors.push(('<b>'+path.join(' > ').capitalize().hyphenate().split('-').join(' ').capitalize()+'</b>')+' is invalid:<br>Must be numeric.'+'<br>');683 }684 break;685 /**686 Default687 */688 default:689 break;690 }691 }692 path.pop();693}694/**695 * ensures that the 'options' object contains the 'requiredKeys'696 *697 */698RPG.Constraints.requiredOptions = function(options,requiredKeys,logger,callback,errors) {699 errors = errors || [];700 if (!options) {701 errors.push('"options" argument missing.');702 }703 if (!requiredKeys && typeof requiredKeys == 'array') {704 errors.push('"requiredKeys" argument missing or not an array.');705 }706 if (typeof callback != 'function') {707 errors.push('callback must be a function.');708 }709 if (errors && errors.length == 0) {710 var optKeys = Object.keys(options);711 Array.clone(requiredKeys).each(function(key){712 if (optKeys.contains(key)) {713 if (options[key]){714 requiredKeys.erase(key);715 }716 }717 });718 if (requiredKeys.length != 0) {719 errors.push('Missing option values: ' + requiredKeys);720 }721 }722 if (errors && errors.length > 0) {723 ((options && options.user && options.user.logger) || logger) && ((options.user && options.user.logger) || logger).fatal(errors+'');724 callback({725 error : errors726 });727 return false;728 }729 return true;...

Full Screen

Full Screen

store.js

Source:store.js Github

copy

Full Screen

1import apiFetch from '@wordpress/api-fetch';2import { registerStore } from '@wordpress/data';3let cache = {};4let alreadyFetchedOptions = false;5const actions = {6 *publishOptions( options ) {7 yield {8 type: 'IO_PUBLISH_OPTIONS',9 options,10 };11 return {12 type: 'PUBLISH_OPTIONS',13 options,14 };15 },16 updateOptions( options ) {17 return {18 type: 'UPDATE_OPTIONS',19 options,20 };21 },22 fetchOptions() {23 return {24 type: 'IO_FETCH_OPTIONS',25 };26 },27 resetLocalChanges() {28 return {29 type: 'RESET_OPTIONS',30 options: cache,31 };32 },33};34/**35 * Store API36 *37 * Selectors under `wp.data.select( STORE_NAME )`:38 *39 * - getOption( String optionName )40 * - hasLocalChanges()41 *42 * Actions under `wp.data.dispatch( STORE_NAME )`:43 *44 * - updateOptions( Object optionsToUpdate )45 * - publishOptions( Object optionsToUpdate )46 * - resetLocalChanges()47 *48 * @param {string} storeName Name of the store.49 * @param {string} optionsPath REST path used to interact with the options API.50 */51export default ( storeName, optionsPath ) => {52 registerStore( storeName, {53 reducer( state, action ) {54 switch ( action.type ) {55 case 'UPDATE_OPTIONS':56 case 'RESET_OPTIONS':57 case 'PUBLISH_OPTIONS':58 return {59 ...state,60 ...action.options,61 };62 }63 return state;64 },65 actions,66 selectors: {67 getOption( state, key ) {68 return state ? state[ key ] : undefined;69 },70 hasLocalChanges( state ) {71 return !! state && Object.keys( cache ).some( ( key ) => cache[ key ] !== state[ key ] );72 },73 },74 resolvers: {75 // eslint-disable-next-line no-unused-vars76 *getOption( key ) {77 if ( alreadyFetchedOptions ) {78 return; // do nothing79 }80 let options;81 try {82 alreadyFetchedOptions = true;83 options = yield actions.fetchOptions();84 } catch ( error ) {85 options = {};86 }87 cache = options;88 return {89 type: 'UPDATE_OPTIONS',90 options,91 };92 },93 },94 controls: {95 IO_FETCH_OPTIONS() {96 return apiFetch( { path: optionsPath } );97 },98 IO_PUBLISH_OPTIONS( { options } ) {99 cache = options; // optimistically update the cache100 return apiFetch( {101 path: optionsPath,102 method: 'POST',103 data: {104 ...options,105 },106 } );107 },108 },109 } );...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1import {merge} from 'lodash';2import {OPTIONS_CHANGE_ACTION} from './actions/index';3export function createDeepProperty({ optionsPath, value }) {4 const obj = {};5 const stopIndex = optionsPath.length - 1;6 return optionsPath.reduce((prev, current, currentIndex) => {7 if (currentIndex === stopIndex) {8 prev[current] = value;9 return obj;10 }11 return prev[current] = {};12 }, obj);13}14export function createPluginsReducer(namespace, fullState) {15 const initialState = fullState[namespace];16 return (state = initialState, action) => {17 switch (action.type) {18 case OPTIONS_CHANGE_ACTION: {19 if (action.optionsPath[0] !== namespace) {20 return state;21 } 22 // NOTE: remove namespace from path;23 const [, ...optionsPath] = action.optionsPath;24 const newFragment = createDeepProperty({ optionsPath, value: action.value });25 return merge({...state}, newFragment);26 }27 default:28 return state;29 }30 };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const optionsPath = require('stryker-parent').optionsPath;2module.exports = function(config) {3 config.set({4 jest: {5 config: require(optionsPath('jest.config.js'))6 }7 });8};

Full Screen

Using AI Code Generation

copy

Full Screen

1var options = require('stryker-parent').optionsPath;2var config = require(options('stryker.conf.js'));3var options = require('stryker-parent').optionsPath;4var config = require(options('stryker.conf.js'));5module.exports = function (config) {6 config.set({7 });8};9module.exports = function (config) {10 config.set({11 });12};13module.exports = function (config) {14 config.set({15 });16};17module.exports = function (config) {18 config.set({19 });20};21module.exports = function (config) {22 config.set({

Full Screen

Using AI Code Generation

copy

Full Screen

1var options = require('stryker-parent').optionsPath('test');2console.log(options);3module.exports = function (config) {4 config.set({5 });6};7{ testRunner: 'karma',8 files: [ 'test.js' ] }

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var path = require('path');3module.exports = function (config) {4 config.set({5 optionsPath: path.join(parent.optionsPath, 'karma.conf.js')6 });7};8module.exports = function (config) {9 config.set({10 });11};

Full Screen

Using AI Code Generation

copy

Full Screen

1var optionsPath = require('stryker-parent').optionsPath;2var strykerOptions = require(optionsPath('stryker.conf.js'));3console.log(strykerOptions);4{ testFramework: 'jasmine',5 karma: { config: [Object] },6 karmaConfigFile: 'karma.conf.js' }

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 stryker-parent 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