Best JavaScript code snippet using storybook-root
index.js
Source:index.js
1const express = require('express');2const fs = require('fs');3const goodsRoutes = express.Router();4const urls = {5 //è·åæ¯ä¸ç±»ååå表6 getOneKindList: '/getOneKindList',7 //è·åä¸ä¸ªåå8 getOneBook: '/getOneBook',9 //è·åå表轮æå¾10 getOneKindSlider: '/getOneKindSlider',11 //è·åææåç±»ICON12 getAllKindsIconList: '/getAllKindsIconList'13};14const booksPosition = './mock/bookList.json';15let read = callback => {16 fs.readFile(booksPosition, 'utf8', (err, data) => {17 if (data.length === 0) {18 data = [];19 } else {20 data = JSON.parse(data);21 }22 callback(err, data);23 });24};25let write = (data, callback) => {26 fs.writeFile(booksPosition, JSON.stringify(data), callback);27};28//è·åæä¸ç±»ååçä¿¡æ¯ï¼å¹¶ä¸å¯ä»¥éæ©è·åè¿ç±»ååçæ°éåå移éï¼29// http://localhost:9999/api/books/getOneKindList?kindId=1&limit=6&offset=130goodsRoutes.get(urls.getOneKindList, (req, res) => {31 //kidåæ°é误32 if (typeof req.query.kindId === 'undefined' || isNaN(parseInt(req.query.kindId)) || parseInt(req.query.kindId) < 0) return res.send({33 code: 1,34 msg: 'kidåæ°é误ï¼'35 });36 //offsetæ¯å¦ä¼ éè¿æ¥37 if (typeof req.query.offset !== 'undefined') {38 //offsetåæ°é误39 if (isNaN(parseInt(req.query.offset)) || parseInt(req.query.offset) < 0) {40 return res.send({41 code: 1,42 msg: 'offsetåæ°é误ï¼'43 });44 }45 } else {46 req.query.offset = 1;47 }48 //limitæ¯å¦ä¼ éè¿æ¥49 if (typeof req.query.limit !== 'undefined') {50 //limitåæ°é误51 if (isNaN(parseInt(req.query.limit)) || parseInt(req.query.limit) < 0) {52 return res.send({53 code: 1,54 msg: 'limitåæ°é误ï¼'55 });56 }57 } else {58 req.query.limit = 5;59 }60 let kinds = [];61 read((err, data) => {62 if (err) return res.send({code: 1, msg: 'æå¡å¨åºç°é误ï¼'});63 kinds = data;64 let kind = kinds.find(item => item.kindId === parseInt(req.query.kindId));65 if (kind) {66 let oneKindBooks = kind/*.list*/;67 let kindId = oneKindBooks.kindId;68 let kindName = oneKindBooks.kindName;69 let kindIcon = oneKindBooks.kindIcon;70 let kindSliderImgs = oneKindBooks.kindSliderImgs;71 let oneKindBookList = oneKindBooks.list.slice(parseInt(req.query.offset) - 1, parseInt(req.query.offset) - 1 + parseInt(req.query.limit));72 let hasMore = true;73 if (parseInt(req.query.offset) + parseInt(req.query.limit) > oneKindBooks.length) {74 hasMore = false;75 }76 res.send({77 code: 0,78 msg: 'è·åæå',79 limit: parseInt(req.query.limit),80 offset: parseInt(req.query.offset),81 page: parseInt(req.query.offset) / parseInt(req.query.limit) + 1,82 pageNum: Math.ceil(oneKindBookList.length / req.query.limit),83 total: oneKindBookList.length,84 hasMore: hasMore,85 /*data: goodsList.slice(parseInt(req.query.offset) - 1, parseInt(req.query.offset) - 1 + parseInt(req.query.limit))*/86 data:{87 "kindId": kindId,88 "kindName": kindName,89 "kindIcon": kindIcon,90 "kindSliderImgs":kindSliderImgs,91 "list":oneKindBookList92 }93 });94 } else {95 res.send({code: 1, msg: 'æ¤åç±»ä¸åå¨ï¼'});96 }97 });98});99//è·åæç§åç±»çè½®æå¾è½®æå¾100// http://localhost:9999/api/books/getOneKindSlider?kindId=1101goodsRoutes.get(urls.getOneKindSlider, (req, res) => {102 //kidåæ°é误103 if (typeof req.query.kindId === 'undefined' || isNaN(parseInt(req.query.kindId)) || parseInt(req.query.kindId) < 0) return res.send({104 code: 1,105 msg: 'kindIdåæ°é误ï¼'106 });107 read((err, data) => {108 if (err) return res.send({code: 1, msg: 'æå¡å¨åºç°é误ï¼'});109 let kind = data.find(item => item.kindId === parseInt(req.query.kindId));110 if (kind) {111 res.send({112 code: 0,113 msg: 'è·åæå',114 kindId:kind.kindId,115 kindName:kind.kindName,116 data: kind.kindSliderImgs117 });118 } else {119 res.send({code: 1, msg: 'æ¤åç±»ä¸åå¨ï¼'});120 }121 });122});123//è·åä¸ä¸ªåå124//http://localhost:9999/api/books/getOneBook?kindId=2&bookId=1125goodsRoutes.get(urls.getOneBook, (req, res) => {126 //kindIdåæ°é误127 if (typeof req.query.kindId === 'undefined' || isNaN(parseInt(req.query.kindId)) || parseInt(req.query.kindId) < 0) return res.send({128 code: 1,129 msg: 'kindIdåæ°é误ï¼'130 });131 //bookIdåæ°é误132 if (typeof req.query.bookId === 'undefined' || isNaN(parseInt(req.query.bookId)) || parseInt(req.query.bookId) < 0) return res.send({133 code: 1,134 msg: 'bookIdåæ°é误ï¼'135 });136 read((err, data) => {137 if (err) return res.send({code: 1, msg: 'æå¡å¨åºç°é误ï¼'});138 let kind = data.find(item => item.kindId === parseInt(req.query.kindId));139 if (kind) {140 let books = kind.list.find(item => item.bookId === parseInt(req.query.bookId));141 if (books) {142 res.send({143 code: 0,144 msg: 'è·åæå',145 kindId:req.query.kindId,146 kindName:kind.kindName,147 data: books148 });149 } else {150 res.send({code: 1, msg: 'æ¤ååä¸åå¨ï¼'});151 }152 } else {153 res.send({code: 1, msg: 'æ¤åç±»ä¸åå¨ï¼'});154 }155 });156});157//è·åææåç±»ICON158goodsRoutes.get(urls.getAllKindsIconList, (req, res) => {159 fs.readFile('./mock/allKindsIconList.json', 'utf8', (err, data) => {160 if (err) return res.send({code: 1, msg: 'æå¡å¨åºç°é误ï¼'});161 res.send({code: 0, msg: 'è·åæå', data: JSON.parse(data)});162 });163});...
AtlasLoadManager.ts
Source:AtlasLoadManager.ts
1/**2* name 3*/4module manager{5 import Texture = laya.resource.Texture;6 import Handler = laya.utils.Handler;7 import Animation = Laya.Animation;8 export class AtlasLoadManager{9 /*åä¾*/10 private static _instance:AtlasLoadManager;11 /*å·²å è½½å¾éçå称ï¼ä¸å¸¦åç¼ï¼*/12 private _loadAtlasAry:Array<string>;13 /*å·²å è½½å¨ç»çå称ï¼ä¸å¸¦åç¼ï¼*/14 private _loadAniAry:Array<string>;15 /*临æ¶èµæºåå*/16 private _assetName:string;17 constructor(){18 this._loadAtlasAry = new Array<string>();19 this._loadAniAry = new Array<string>();20 }21 public static get instance():AtlasLoadManager{22 if(this._instance == null){23 this._instance = new AtlasLoadManager();24 }25 return this._instance;26 }27 //tryè·å纹ç28 private tryGetTextureInCache(assetName:string,kindID:number,statusID:number):Texture{29 var tex:Texture = null;30 /*æªå è½½*/31 if(this._loadAtlasAry.indexOf(this._assetName) == -1){32 return null;33 }34 /*å·²å è½½å¾é*/35 else{36 var texURL:string = assetName + "_" + kindID + "_" + statusID;37 var URLAry:Array<string> = Laya.Loader.getAtlas("res/atlas/" + assetName + ".atlas");38 if(URLAry.length <= 0){39 console.assert(false,"å¾éurlé误");40 }41 for (var i:number = 0; i<URLAry.length; i++){42 var url:string = URLAry[i]43 if(url.indexOf(texURL) != -1){44 tex = Laya.loader.getRes(url);45 break;46 }47 }48 } 49 return tex;50 }51 52 //tryå è½½å¾é53 private tryLoadAtals(assetName:string,kindID:number,statusID:number = 0,callBack:Handler):void{54 if(this._loadAtlasAry.indexOf(assetName) == -1){55 var url:string = "res/atlas/" + assetName + ".atlas";56 Laya.loader.load(url,laya.utils.Handler.create(this,this.onLoadAtlasComplete,[assetName,kindID,statusID,callBack]),null,Laya.Loader.ATLAS)57 }58 }59 //å è½½å®æ¯60 private onLoadAtlasComplete(assetName:string,kindID:number,statusID:number,callBack:Handler):void{61 var tex:Texture = null;62 this._loadAtlasAry.push(this._assetName);63 tex = this.tryGetTextureInCache(assetName,kindID,statusID);64 if(tex == null){65 console.assert(false,"Texture为空ï¼");66 }67 if(callBack != null){68 callBack.runWith(tex);69 }70 }71 //tryè·å纹ç,èªå¨è¯å«ç¼åä¸æ¯å¦ææ¤çº¹çï¼æ åå è½½ï¼æåä»ç¼åä¸è·å72 public tryGetAtlas(flagName:string,typeStr:string,kindID:number = -1,statusID:number = -1, varsData:Object = null, callBack:Handler = null):void{73 this._assetName = flagName + "_" +typeStr;74 if(flagName == GameObjectEnum.TEXTURE_FLAG){75 var tex:Texture = null;76 tex = this.tryGetTextureInCache(this._assetName,kindID,statusID);77 if(tex == null){78 this.tryLoadAtals(this._assetName,kindID,statusID,callBack);79 }80 else{81 if(callBack != null){82 callBack.runWith(tex);83 }84 }85 }86 else if(flagName == GameObjectEnum.ANIMATION_FLAG){ 87 if(this._loadAniAry.indexOf(this._assetName) == -1){88 if(varsData == null){89 console.assert(false,"å¨ç»åæ°æªè®¾ç½®ï¼")90 }91 this.tryGetAnimation(this._assetName,kindID,statusID,varsData["aniLength"],callBack);92 }else{93 if(callBack != null){94 // Laya.Animation.createFrames(this.aniUrls(this._assetName,kindID,statusID,length),this._assetName);95 callBack.runWith(this._assetName);96 }97 }98 99 }100 else{101 console.assert(false,flagName + "ä¸åå¨")102 }103 }104 //tryè·å¾å¨ç» èµæºåå(assetName)ä¸å¨ç»æ¨¡æ¿ååä¿æä¸è´105 private tryGetAnimation(assetName:string,kindID:number,statusID:number,length:number,callBack:Handler):void{ 106 if(this._loadAniAry.indexOf(assetName) == -1){107 this.tryLoadAniAtals(assetName, kindID, statusID,length, callBack);108 }109 else{110 if(callBack != null){111 callBack.runWith(assetName);112 }113 }114 }115 //tryå è½½å¨ç»å¾é116 private tryLoadAniAtals(assetName:string,kindID:number,statusID:number,length:number,callBack:Handler):void{117 var url:string = "res/atlas/" + assetName + ".atlas";118 Laya.loader.load(url,laya.utils.Handler.create(this,this.onLoadAniComplete,[assetName,kindID,statusID,length,callBack]),null,Laya.Loader.ATLAS)119 }120 //å¨ç»å è½½å®æ¯ 121 private onLoadAniComplete(assetName:string,kindID:number,statusID:number,length:number,callBack:Handler):void{122 this._loadAniAry.push(assetName);123 //æå
å¾éæ¾ç½®å¨ç¼åå
124 Laya.Animation.createFrames(this.aniUrls(assetName,kindID,statusID,length),assetName);125 if(callBack != null){126 callBack.runWith(assetName);127 } 128 }129 //è·å¾å¨ç»è·¯å¾(ç®ååªæ¯æpng å¾
æ·»å ...)130 private aniUrls(assetName:string,kindID:number,statusID:number,length:number):any{131 var urls:any = [];132 for(var i:number = 1; i < length+1; i++){133 urls.push(assetName + "/" + assetName + "_" + kindID+ "_" + statusID + "_" + i +".png");134 }135 return urls;136 }137 }...
listController.js
Source:listController.js
1const { json } = require("body-parser");2const User = require("../models/userAuth");3const listController = {4 handleSave: (req, res) => {5 let kindID;6 if (req.googleID) kindID = { googleID: req.googleID };7 if (req.facebookID) kindID = { facebookID: req.facebookID };8 User.updateOne({ kindID }, { todoList: req.list }).then((result) => {9 if (result.n === 0) {10 return res.json({ ok: 0 });11 }12 req.flash("saveMessage", "å²åæå");13 return res.json({ ok: 1 });14 });15 },16 save: (req, res, next) => {17 const { googleID, facebookID } = req.session.user;18 const list = JSON.stringify(req.body);19 if (googleID) req.googleID = googleID;20 if (facebookID) req.facebookID = facebookID;21 req.list = list;22 next();23 },24 load: (req, res) => {25 const user = req.session.user;26 let kindID;27 if (user.googleID) kindID = { googleID: user.googleID };28 if (user.facebookID) kindID = { facebookID: user.facebookID };29 User.findOne({ kindID })30 .then((result) => {31 req.flash("saveMessage", "è®åæå");32 return res.json({33 ok: 1,34 todoList: result.todoList,35 });36 })37 .catch((err) => {38 req.flash("saveMessage", "è®å失æ");39 return res.json({ ok: 0 });40 });41 },42};...
Using AI Code Generation
1import React from 'react';2import {storiesOf} from 'storybook-root';3storiesOf('Button', module)4 .add('with text', () => (5 .add('with emoji', () => (6 ));7import React from 'react';8import {storiesOf} from 'storybook-root';9storiesOf('Button', module)10 .add('with text', () => (11 .add('with emoji', () => (12 ));13import React from 'react';14import {storiesOf} from 'storybook-root';15storiesOf('Button', module)16 .add('with text', () => (17 .add('with emoji', () => (18 ));19import React from 'react';20import {storiesOf} from 'storybook-root';21storiesOf('Button', module)22 .add('with text', () => (23 .add('with emoji', () => (24 ));25import React from 'react';26import {storiesOf} from 'storybook-root';27storiesOf('Button', module)28 .add('with text', () => (29 .add('with emoji', () => (30 ));
Using AI Code Generation
1import { storybookRoot } from 'storybook-root';2storybookRoot.kindId('kind');3import { storybookRoot } from 'storybook-root';4storybookRoot.kindId('kind', 'story');5import { storybookRoot } from 'storybook-root';6storybookRoot.kindId('kind', 'story', 'subkind');7import { storybookRoot } from 'storybook-root';8storybookRoot.kindId('kind', 'story', 'subkind', 'substory');9import { storybookRoot } from 'storybook-root';10storybookRoot.kindId('kind', 'story', 'subkind', 'substory', 'subsubkind');11import { storybookRoot } from 'storybook-root';12storybookRoot.kindId('kind', 'story', 'subkind', 'substory', 'subsubkind', 'subsubstory');13import { storybookRoot } from 'storybook-root';14storybookRoot.kindId('kind', 'story', 'subkind', 'substory', 'subsubkind', 'subsubstory', 'subsubsubkind');15import { storybookRoot } from 'storybook-root';16storybookRoot.kindId('kind', 'story', 'subkind', 'substory', 'subsubkind', 'subsubstory', 'subsubsubkind', 'subsubsubstory');17import { storybookRoot } from 'storybook-root';18storybookRoot.kindId('kind', 'story', 'subkind', 'substory', 'subsubkind', 'subsubstory', 'subsubsubkind', 'subsubsubstory', 'subsubsubsubkind');19import { storybookRoot } from 'storybook-root';20storybookRoot.kindId('kind
Using AI Code Generation
1import { kindId } from 'storybook-root';2console.log(kindId('Button'));3import { kindId } from 'storybook-root';4console.log(kindId('Button'));5import { kindId } from 'storybook-root';6console.log(kindId('Button'));
Using AI Code Generation
1import { kindId } from 'storybook-root';2console.log(kindId('My Story'));3import { kindId } from 'storybook-root';4console.log(kindId('My Story'));5import { kindId } from 'storybook-root';6console.log(kindId('My Story'));7import { kindId } from 'storybook-root';8console.log(kindId('My Story'));9import { kindId } from 'storybook-root';10console.log(kindId('My Story'));11import { kindId } from 'storybook-root';12console.log(kindId('My Story'));13import { kindId } from 'storybook-root';14console.log(kindId('My Story'));15import { kindId } from 'storybook-root';16console.log(kindId('My Story'));17import { kindId } from 'storybook-root';18console.log(kindId('My Story'));19import { kindId } from 'storybook-root';20console.log(kindId('My Story'));21import { kindId } from 'storybook-root';22console.log(kindId('My Story'));23import { kindId } from 'storybook-root';24console.log(kindId('My Story'));
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!