Best JavaScript code snippet using playwright-internal
data.js
Source:data.js
1export const questions = [2 {3 question: 'ÐÑбеÑи ÑвеÑ',4 type: 'withImage',5 options: [6 {7 image: '/color/black.jpg',8 id: 0,9 points: {10 useState: 10,11 useReducer: 5,12 useCallback: 3,13 useImperativeHandle: 6,14 useEffect: 5,15 useRef: 7,16 useLayoutEffect: 317 }18 },19 {20 image: '/color/blue.jpg',21 id: 1,22 points: {23 useState: 4,24 useReducer: 10,25 useCallback: 3,26 useImperativeHandle: 5,27 useEffect: 4,28 useRef: 4,29 useLayoutEffect: 330 }31 },32 {33 image: '/color/gray.jpg',34 id: 2,35 points: {36 useState: 3,37 useReducer: 4,38 useCallback: 10,39 useImperativeHandle: 4,40 useEffect: 3,41 useRef: 5,42 useLayoutEffect: 443 }44 },45 {46 image: '/color/green.jpg',47 id: 3,48 points: {49 useState: 3,50 useReducer: 1,51 useCallback: 5,52 useImperativeHandle: 10,53 useEffect: 3,54 useRef: 5,55 useLayoutEffect: 156 }57 },58 {59 image: '/color/orange.jpg',60 id: 4,61 points: {62 useState: 1,63 useReducer: 8,64 useCallback: 3,65 useImperativeHandle: 5,66 useEffect: 10,67 useRef: 1,68 useLayoutEffect: 769 }70 },71 {72 image: '/color/pink.jpg',73 id: 5,74 points: {75 useState: 3,76 useReducer: 4,77 useCallback: 3,78 useImperativeHandle: 9,79 useEffect: 6,80 useRef: 10,81 useLayoutEffect: 482 }83 },84 {85 image: '/color/purple.jpg',86 id: 6,87 points: {88 useState: 1,89 useReducer: 6,90 useCallback: 5,91 useImperativeHandle: 2,92 useEffect: 5,93 useRef: 5,94 useLayoutEffect: 1095 }96 },97 {98 image: '/color/red.jpg',99 id: 7,100 points: {101 useState: 8,102 useReducer: 5,103 useCallback: 1,104 useImperativeHandle: 3,105 useEffect: 9,106 useRef: 8,107 useLayoutEffect: 7108 }109 },110 {111 image: '/color/yellow.jpg',112 id: 8,113 points: {114 useState: 3,115 useReducer: 9,116 useCallback: 5,117 useImperativeHandle: 3,118 useEffect: 1,119 useRef: 1,120 useLayoutEffect: 4121 }122 }123 ]124 },125 {126 question: 'ÐÑбеÑи ÑилÑм',127 type: 'withImage',128 options: [129 {130 image: '/movie/brother.png',131 text: '"ÐÑаÑ"',132 id: 0,133 points: {134 useState: 10,135 useReducer: 5,136 useCallback: 2,137 useImperativeHandle: 6,138 useEffect: 6,139 useRef: 7,140 useLayoutEffect: 3141 }142 },143 {144 image: '/movie/zhmurki.png',145 text: '"ÐмÑÑки"',146 id: 1,147 points: {148 useState: 4,149 useReducer: 10,150 useCallback: 5,151 useImperativeHandle: 5,152 useEffect: 4,153 useRef: 4,154 useLayoutEffect: 3155 }156 },157 {158 image: '/movie/indiana.png',159 text: '"Ðндиана ÐÐ¶Ð¾Ð½Ñ Ð¸ поÑледний кÑеÑÑовÑй поÑ
од"',160 id: 2,161 points: {162 useState: 5,163 useReducer: 4,164 useCallback: 10,165 useImperativeHandle: 4,166 useEffect: 3,167 useRef: 4,168 useLayoutEffect: 4169 }170 },171 {172 image: '/movie/godfather.png',173 text: '"ÐÑеÑÑнÑй оÑеÑ"',174 id: 3,175 points: {176 useState: 3,177 useReducer: 1,178 useCallback: 8,179 useImperativeHandle: 10,180 useEffect: 3,181 useRef: 6,182 useLayoutEffect: 1183 }184 },185 {186 image: '/movie/beauty.png',187 text: '"ÐÑаÑоÑка"',188 id: 4,189 points: {190 useState: 1,191 useReducer: 7,192 useCallback: 3,193 useImperativeHandle: 5,194 useEffect: 10,195 useRef: 8,196 useLayoutEffect: 7197 }198 },199 {200 image: '/movie/avengers.png',201 text: '"ÐÑÑиÑели: Ñинал"',202 id: 5,203 points: {204 useState: 3,205 useReducer: 4,206 useCallback: 7,207 useImperativeHandle: 9,208 useEffect: 6,209 useRef: 10,210 useLayoutEffect: 3211 }212 },213 {214 image: '/movie/revenant.png',215 text: '"ÐÑживÑий"',216 id: 6,217 points: {218 useState: 1,219 useReducer: 6,220 useCallback: 5,221 useImperativeHandle: 2,222 useEffect: 5,223 useRef: 5,224 useLayoutEffect: 10225 }226 },227 {228 image: '/movie/nocountry.png',229 text: '"СÑаÑикам здеÑÑ Ð½Ðµ меÑÑо"',230 id: 7,231 points: {232 useState: 8,233 useReducer: 5,234 useCallback: 6,235 useImperativeHandle: 9,236 useEffect: 7,237 useRef: 8,238 useLayoutEffect: 7239 }240 },241 {242 image: '/movie/animals.png',243 text: '"Ð¢Ð°Ð¹Ð½Ð°Ñ Ð¶Ð¸Ð·Ð½Ñ Ð´Ð¾Ð¼Ð°ÑниÑ
живоÑнÑÑ
2"',244 id: 8,245 points: {246 useState: 3,247 useReducer: 3,248 useCallback: 5,249 useImperativeHandle: 3,250 useEffect: 8,251 useRef: 7,252 useLayoutEffect: 4253 }254 }255 ]256 },257 {258 question: 'ÐÑбеÑи пеÑнÑ',259 type: 'withImage',260 options: [261 {262 image: '/song/despacito.png',263 text: 'Luis Fonsi: "Despacito"',264 id: 0,265 points: {266 useState: 6,267 useReducer: 5,268 useCallback: 6,269 useImperativeHandle: 6,270 useEffect: 5,271 useRef: 7,272 useLayoutEffect: 10273 }274 },275 {276 image: '/song/adele.png',277 text: 'Adele: "Rolling in the deep"',278 id: 1,279 points: {280 useState: 4,281 useReducer: 4,282 useCallback: 6,283 useImperativeHandle: 5,284 useEffect: 5,285 useRef: 10,286 useLayoutEffect: 3287 }288 },289 {290 image: '/song/beegees.png',291 text: 'Bee Gees: "How deep is your love"',292 id: 2,293 points: {294 useState: 5,295 useReducer: 4,296 useCallback: 7,297 useImperativeHandle: 4,298 useEffect: 10,299 useRef: 6,300 useLayoutEffect: 4301 }302 },303 {304 image: '/song/hellsbells.png',305 text: 'AC/DC: "Hells bells"',306 id: 3,307 points: {308 useState: 3,309 useReducer: 1,310 useCallback: 8,311 useImperativeHandle: 10,312 useEffect: 3,313 useRef: 5,314 useLayoutEffect: 1315 }316 },317 {318 image: '/song/survivor.png',319 text: 'Survivor: "Eye of the tiger"',320 id: 4,321 points: {322 useState: 1,323 useReducer: 5,324 useCallback: 10,325 useImperativeHandle: 5,326 useEffect: 2,327 useRef: 1,328 useLayoutEffect: 7329 }330 },331 {332 image: '/song/gaye.png',333 text: 'Marvin Gaye: "Lets get it on"',334 id: 5,335 points: {336 useState: 3,337 useReducer: 10,338 useCallback: 7,339 useImperativeHandle: 6,340 useEffect: 6,341 useRef: 1,342 useLayoutEffect: 6343 }344 },345 {346 image: '/song/pharell.png',347 text: 'Pharell Williams: "Happy"',348 id: 6,349 points: {350 useState: 10,351 useReducer: 6,352 useCallback: 5,353 useImperativeHandle: 2,354 useEffect: 5,355 useRef: 5,356 useLayoutEffect: 1357 }358 },359 {360 image: '/song/shortpairs.png',361 text: 'Shortparis: "СÑÑаÑно"',362 id: 7,363 points: {364 useState: 8,365 useReducer: 5,366 useCallback: 1,367 useImperativeHandle: 3,368 useEffect: 9,369 useRef: 8,370 useLayoutEffect: 7371 }372 },373 {374 image: '/song/arctic.png',375 text: 'Arctic Monkeys: "Four out of five"',376 id: 8,377 points: {378 useState: 3,379 useReducer: 9,380 useCallback: 5,381 useImperativeHandle: 3,382 useEffect: 1,383 useRef: 1,384 useLayoutEffect: 4385 }386 }387 ]388 },389 {390 question: 'Ðде ÑÑ Ð² пÑÑниÑÑ Ð²ÐµÑеÑом?',391 type: 'text',392 options: [393 {394 text: 'Со Ñвоей вÑоÑой половинкой',395 id: 2,396 points: {397 useState: 5,398 useReducer: 4,399 useCallback: 10,400 useImperativeHandle: 4,401 useEffect: 3,402 useRef: 4,403 useLayoutEffect: 4404 }405 },406 {407 text: 'ÐÑÑ
Ð°Ñ Ñ Ð´ÑÑзÑÑми',408 id: 3,409 points: {410 useState: 3,411 useReducer: 1,412 useCallback: 5,413 useImperativeHandle: 10,414 useEffect: 3,415 useRef: 4,416 useLayoutEffect: 1417 }418 },419 {420 text: 'Ðа Ñвиданке',421 id: 0,422 points: {423 useState: 10,424 useReducer: 5,425 useCallback: 8,426 useImperativeHandle: 6,427 useEffect: 7,428 useRef: 7,429 useLayoutEffect: 3430 }431 },432 {433 text: 'СплÑ',434 id: 4,435 points: {436 useState: 1,437 useReducer: 8,438 useCallback: 5,439 useImperativeHandle: 5,440 useEffect: 10,441 useRef: 1,442 useLayoutEffect: 7443 }444 },445 {446 text: 'ТÑÑÑÑÑÑ Ð² клÑбе',447 id: 5,448 points: {449 useState: 3,450 useReducer: 4,451 useCallback: 7,452 useImperativeHandle: 9,453 useEffect: 6,454 useRef: 10,455 useLayoutEffect: 8456 }457 },458 {459 text: 'СмоÑÑÑ ÐºÐ¸Ð½Ð¾ дома',460 id: 6,461 points: {462 useState: 1,463 useReducer: 6,464 useCallback: 5,465 useImperativeHandle: 2,466 useEffect: 5,467 useRef: 5,468 useLayoutEffect: 10469 }470 },471 {472 text: 'ÐÑÐ¼Ð°Ñ Ð¾ бÑвÑей',473 id: 1,474 points: {475 useState: 4,476 useReducer: 10,477 useCallback: 1,478 useImperativeHandle: 5,479 useEffect: 5,480 useRef: 4,481 useLayoutEffect: 3482 }483 },484 {485 text: 'ÐгÑÐ°Ñ Ð² наÑÑолки',486 id: 7,487 points: {488 useState: 8,489 useReducer: 5,490 useCallback: 1,491 useImperativeHandle: 3,492 useEffect: 9,493 useRef: 8,494 useLayoutEffect: 7495 }496 }497 ]498 },499 {500 question: 'ÐÑбеÑи ÑÑпеÑÑпоÑобноÑÑÑ',501 type: 'text',502 options: [503 {504 text: 'ÐевидимоÑÑÑ',505 id: 0,506 points: {507 useState: 10,508 useReducer: 5,509 useCallback: 8,510 useImperativeHandle: 6,511 useEffect: 7,512 useRef: 7,513 useLayoutEffect: 3514 }515 },516 {517 text: 'ÐÑÑеÑеÑÑвие во вÑемени',518 id: 1,519 points: {520 useState: 4,521 useReducer: 10,522 useCallback: 6,523 useImperativeHandle: 5,524 useEffect: 3,525 useRef: 4,526 useLayoutEffect: 3527 }528 },529 {530 text: 'ÐиÑаÑÑ Ð¿Ð¾Ð¿ÑлÑÑнÑе ÑвиÑÑ',531 id: 2,532 points: {533 useState: 4,534 useReducer: 4,535 useCallback: 10,536 useImperativeHandle: 4,537 useEffect: 3,538 useRef: 5,539 useLayoutEffect: 4540 }541 },542 {543 text: 'СÑпеÑÑила',544 id: 3,545 points: {546 useState: 3,547 useReducer: 1,548 useCallback: 8,549 useImperativeHandle: 10,550 useEffect: 3,551 useRef: 4,552 useLayoutEffect: 1553 }554 },555 {556 text: 'СÑпеÑÑолеÑаÑноÑÑÑ',557 id: 4,558 points: {559 useState: 1,560 useReducer: 3,561 useCallback: 4,562 useImperativeHandle: 5,563 useEffect: 10,564 useRef: 1,565 useLayoutEffect: 7566 }567 },568 {569 text: 'ТелепоÑÑаÑиÑ',570 id: 5,571 points: {572 useState: 3,573 useReducer: 4,574 useCallback: 7,575 useImperativeHandle: 3,576 useEffect: 6,577 useRef: 10,578 useLayoutEffect: 4579 }580 },581 {582 text: 'ЧиÑаÑÑ Ð¼ÑÑли',583 id: 6,584 points: {585 useState: 1,586 useReducer: 6,587 useCallback: 5,588 useImperativeHandle: 2,589 useEffect: 5,590 useRef: 5,591 useLayoutEffect: 10592 }593 },594 {595 text: 'ÐÑÑаÑÑ Ð¿Ð¾Ð´ водой',596 id: 7,597 points: {598 useState: 8,599 useReducer: 5,600 useCallback: 1,601 useImperativeHandle: 3,602 useEffect: 9,603 useRef: 8,604 useLayoutEffect: 7605 }606 }607 ]608 }609]610export const hooks = {611 useState: {612 description: 'Ð¢Ñ useState!',613 text: 'ÐозвÑаÑÐ°ÐµÑ Ð·Ð½Ð°Ñение Ñ ÑоÑÑоÑнием и ÑÑнкÑÐ¸Ñ Ð´Ð»Ñ ÐµÐ³Ð¾ обновлениÑ.',614 link: 'https://reactjs.org/docs/hooks-reference.html#usestate'615 },616 useReducer: {617 description: 'Ð¢Ñ useReducer!',618 text:619 'ÐлÑÑеÑнаÑива Ð´Ð»Ñ useState. ÐÑÐ¸Ð½Ð¸Ð¼Ð°ÐµÑ ÑедÑÑÐµÑ Ñипа (state, action) => newState и возвÑаÑÐ°ÐµÑ ÑекÑÑее ÑоÑÑоÑние в паÑе Ñ Ð¼ÐµÑодом dispatch. (ÐÑли Ð²Ñ Ð·Ð½Ð°ÐºÐ¾Ð¼Ñ Ñ Redux, Ð²Ñ Ñже знаеÑе, как ÑÑо ÑабоÑаеÑ.)',620 link: 'https://reactjs.org/docs/hooks-reference.html#usereducer'621 },622 useCallback: {623 description: 'Ð¢Ñ useCallback!',624 text: 'ÐозвÑаÑÐ°ÐµÑ Ð¼ÐµÐ¼Ð¾Ð¸Ð·Ð¸ÑованнÑй колбÑк.',625 link: 'https://reactjs.org/docs/hooks-reference.html#usecallback'626 },627 useImperativeHandle: {628 description: 'Ð¢Ñ useImperativeHandle!',629 text:630 'useImperativeHandle наÑÑÑÐ°Ð¸Ð²Ð°ÐµÑ Ð·Ð½Ð°Ñение ÑкземплÑÑа, коÑоÑое пÑедоÑÑавлÑеÑÑÑ ÑодиÑелÑÑким компоненÑам пÑи иÑполÑзовании ref. Ðак вÑегда, в болÑÑинÑÑве ÑлÑÑаев ÑледÑÐµÑ Ð¸Ð·Ð±ÐµÐ³Ð°ÑÑ Ð¸Ð¼Ð¿ÐµÑаÑивного кода, иÑполÑзÑÑÑего ÑÑÑлки. useImperativeHandle должен иÑполÑзоваÑÑÑÑ Ñ forwardRef:',631 link: 'https://reactjs.org/docs/hooks-reference.html#useimperativehandle'632 },633 useEffect: {634 description: 'Ð¢Ñ useEffect!',635 text:636 'ÐÑÐ¸Ð½Ð¸Ð¼Ð°ÐµÑ ÑÑнкÑиÑ, коÑоÑÐ°Ñ ÑодеÑÐ¶Ð¸Ñ Ð¸Ð¼Ð¿ÐµÑаÑивнÑй код, возможно, Ñ ÑÑÑекÑами.',637 link: 'https://reactjs.org/docs/hooks-reference.html#useeffect'638 },639 useRef: {640 description: 'Ð¢Ñ useRef!',641 text:642 'useRef возвÑаÑÐ°ÐµÑ Ð¸Ð·Ð¼ÐµÐ½ÑемÑй ref-обÑекÑ, ÑвойÑÑво .current коÑоÑого иниÑиализиÑÑеÑÑÑ Ð¿ÐµÑеданнÑм аÑгÑменÑом (initialValue). ÐозвÑаÑÑннÑй обÑÐµÐºÑ Ð±ÑÐ´ÐµÑ ÑоÑ
ÑанÑÑÑÑÑ Ð² ÑеÑение вÑего вÑемени жизни компоненÑа.',643 link: 'https://reactjs.org/docs/hooks-reference.html#useref'644 },645 useLayoutEffect: {646 description: 'Ð¢Ñ useLayoutEffect!',647 text:648 'СигнаÑÑÑа иденÑиÑна useEffect, но ÑÑÐ¾Ñ Ñ
Ñк запÑÑкаеÑÑÑ ÑинÑ
Ñонно поÑле вÑеÑ
изменений DOM. ÐÑполÑзÑйÑе его Ð´Ð»Ñ ÑÑÐµÐ½Ð¸Ñ Ð¼Ð°ÐºÐµÑа из DOM и ÑинÑ
Ñонного повÑоÑного ÑендеÑинга. ÐбновлениÑ, запланиÑованнÑе внÑÑÑи useLayoutEffect, бÑдÑÑ Ð¿Ð¾Ð»Ð½Ð¾ÑÑÑÑ Ð¿ÑÐ¸Ð¼ÐµÐ½ÐµÐ½Ñ ÑинÑ
Ñонно пеÑед Ñем, как бÑаÑÐ·ÐµÑ Ð¿Ð¾Ð»ÑÑÐ¸Ñ ÑÐ°Ð½Ñ Ð¾ÑÑÑеÑÑвиÑÑ Ð¾ÑÑиÑовкÑ.',649 link: 'https://reactjs.org/docs/hooks-reference.html#uselayouteffect'650 }...
usePerpetual.js
Source:usePerpetual.js
...28 const [status, setStatus] = useState("--")29 const [accumulatedFunding, setAccumulatedFunding] = useState("--")30 const [myDeposit, setMyDeposit] = useState("0")31 const shareToken = useERC20(shareTokenAddress, account, library, tick)32 const getStatus = useCallback(33 async () => {34 try {35 const result = await perpetualContract.status()36 switch (result) {37 case 0:38 return "Active"39 case 1:40 return "Emergency"41 case 2:42 return "Settlement"43 default:44 return "Unknown"45 }46 } catch (e) {47 return "Error"48 }49 },50 [perpetualContract, account]51 );52 const getShareTokenAddress = useCallback( async () => {53 try {54 return await ammContract.shareTokenAddress()55 } catch (e) {56 return null57 }58 },[ammContract, account])59 const getIndexPrice = useCallback(60 async () => {61 try {62 const result = await ammContract.indexPrice()63 return ethers.utils.formatEther(result.price)64 } catch (e) {65 return "0"66 }67 },68 [ammContract, account]69 );70 const getAccumulatedFunding = useCallback(71 async () => {72 try {73 const result = await ammContract.getAccumulatedFundingPerContract()74 return ethers.utils.formatEther(result)75 } catch (e) {76 return "0"77 }78 },79 [ammContract, account]80 );81 const getAvailableMargin = useCallback(82 async () => {83 try {84 const result = await ammContract.getAvailableMargin()85 return ethers.utils.formatEther(result)86 } catch (e) {87 return "0"88 }89 },90 [ammContract, account]91 );92 const getMarkPrice = useCallback(93 async () => {94 try {95 const output = await ammContract.getMarkPrice()96 return ethers.utils.formatEther(output)97 } catch (e) {98 return "0"99 }100 },101 [ammContract, account]102 );103 const getBuyPrice = useCallback(async (amount) => {104 const result = await ammContract.getBuyPricePublic(ethers.utils.parseEther(`${amount}`))105 return ethers.utils.formatEther(result)106 }, [ammContract, account])107 const getSellPrice = useCallback(async (amount) => {108 const result = await ammContract.getSellPricePublic(ethers.utils.parseEther(`${amount}`))109 return ethers.utils.formatEther(result)110 }, [ammContract, account])111 const deposit = useCallback(112 async (amount) => {113 return await perpetualContract.deposit(114 ethers.utils.parseEther(amount)115 )116 },117 [perpetualContract, account]118 );119 const withdraw = useCallback(120 async (amount) => {121 // TODO : increase gas price122 return await perpetualContract.withdraw(123 ethers.utils.parseEther(amount),124 {125 // gasPrice: 70000000000126 }127 )128 },129 [perpetualContract, account]130 );131 const getDeposit = useCallback(async () => {132 const result = await perpetualContract.totalRawCollateral(account)133 return ethers.utils.formatEther(result)134 }, [perpetualContract, account])135 const getDeadline = () => {136 return ((new Date().valueOf() / 1000) + 86400)137 }138 const getCurrentPrice = useCallback(async () => {139 const result = await ammContract.getCurrentPricePublic()140 return ethers.utils.formatEther(result)141 }, [ammContract, account])142 const buy = useCallback(async (amount) => {143 // TODO : increase gas price144 return await ammContract.buy(ethers.utils.parseEther(`${amount}`), ethers.utils.parseEther(`50000`), 9999999999999, {145 // gasPrice: 70000000000146 })147 }, [ammContract, account])148 const sell = useCallback(async (amount) => {149 // TODO : increase gas price150 return await ammContract.sell(ethers.utils.parseEther(`${amount}`), 0, 9999999999999, {151 // gasPrice: 70000000000152 })153 }, [ammContract, account])154 const addLiquidity = useCallback(async (amount) => {155 // TODO : increase gas price156 return await ammContract.addLiquidity(ethers.utils.parseEther(`${amount}`), { 157 // gasPrice: 70000000000158 })159 }, [ammContract, account])160 const removeLiquidity = useCallback(async (lpAmount) => {161 // TODO : increase gas price162 return await ammContract.removeLiquidity(ethers.utils.parseEther(`${lpAmount}`), {163 // gasPrice: 70000000000164 })165 }, [ammContract, account])166 const getPosition = useCallback(async () => {167 168 const size = await perpetualContract.getPositionSize(account)169 const side = await perpetualContract.getPositionSide(account)170 const positionEntryValue = await perpetualContract.getPositionEntryValue(account)171 let pnl = 0172 if (side === 2) {173 //long174 pnl = (Number(markPrice) * Number(ethers.utils.formatEther(size))) - Number(ethers.utils.formatEther(positionEntryValue))175 } else if (side === 1) {176 //short177 pnl = Number(ethers.utils.formatEther(positionEntryValue)) - (Number(markPrice) * Number(ethers.utils.formatEther(size)))178 }179 return {180 size : ethers.utils.formatEther(size),...
useApi.js
Source:useApi.js
2import { useAxiosContext } from '@hooks/useAxiosContext'3const useApi = () => {4 const { auth, instance } = useAxiosContext()5 const authApi = {6 signUp: useCallback(7 userInfo => {8 return instance.post('/members', userInfo)9 },10 [instance],11 ),12 loginEmail: useCallback(13 userInfo => {14 return instance?.post('/members/login', userInfo)15 },16 [instance],17 ),18 loginKakao: useCallback(19 code => {20 return instance.get(`/oauth/callback/kakao?code=${code}`)21 },22 [instance],23 ),24 checkDuplicates: useCallback(25 email => {26 return instance.get(`/members?email=${email}`)27 },28 [instance],29 ),30 withdrawal: useCallback(31 password => {32 return auth.delete('/members', password)33 },34 [auth],35 ),36 getUserInfo: useCallback(() => {37 return auth.get('/members/me')38 }, [auth]),39 getUserProfile: useCallback(() => {40 return auth.get('/members/mypage')41 }, [auth]),42 getOtherUserProfile: useCallback(43 merberId => {44 return instance.get(`/members/${merberId}`)45 },46 [instance],47 ),48 modifyUserInfo: useCallback(49 userInfo => {50 return auth.patch('/members/me', userInfo)51 },52 [auth],53 ),54 }55 const userApi = {56 getUserLikeArticles: useCallback(57 ({ tradeStatusCode, params }) => {58 return auth.get(59 `/articles/like-articles?tradeStatusCode=${tradeStatusCode}`,60 { params },61 )62 },63 [auth],64 ),65 getUserOfferArticles: useCallback(66 ({ tradeStatusCode, params }) => {67 return auth.get(`/articles/offers?tradeStatusCode=${tradeStatusCode}`, {68 params,69 })70 },71 [auth],72 ),73 getUserTradingAtricles: useCallback(74 ({ memberId, params }) => {75 return instance.get(76 `/articles?memberId=${memberId}&tradeStatusCode=4`,77 {78 params,79 },80 )81 },82 [instance],83 ),84 getUserCompletedArticles: useCallback(85 ({ memberId, params }) => {86 return instance.get(87 `/articles?memberId=${memberId}&tradeStatusCode=8`,88 {89 params,90 },91 )92 },93 [instance],94 ),95 getUserBuyReviews: useCallback(96 ({ memberId, params }) => {97 return auth.get(`/reviews?memberId=${memberId}&role=buyer`, {98 params,99 })100 },101 [auth],102 ),103 getUserSellReviews: useCallback(104 ({ memberId, params }) => {105 return auth.get(`/reviews?memberId=${memberId}&role=seller`, {106 params,107 })108 },109 [auth],110 ),111 getUserReview: useCallback(112 articleId => {113 return auth.get(`/reviews/me?articleId=${articleId}`)114 },115 [auth],116 ),117 postReview: useCallback(118 ({ articleId, payload }) => {119 return auth.post(`/reviews?articleId=${articleId}`, payload)120 },121 [auth],122 ),123 }124 const reviewApi = {125 getBuyReviews: useCallback(126 memberId => {127 return instance.get(`/reviews?memberId=${memberId}&status=buy`)128 },129 [instance],130 ),131 getSellReviews: useCallback(132 memberId => {133 return instance.get(`/reviews?memberId=${memberId}&status=sell`)134 },135 [instance],136 ),137 postReview: useCallback(138 ({ offerId, memberId, content }) => {139 return auth.post(140 `/reviews/offers/${offerId}?toMember=${memberId}`,141 content,142 )143 },144 [auth],145 ),146 }147 const articleApi = {148 searchArticlesWithAuth: useCallback(149 params => {150 return auth.get(`/search`, { params })151 },152 [auth],153 ),154 searchArticles: useCallback(155 params => {156 return instance.get(`/search`, { params })157 },158 [instance],159 ),160 searchFilterArticles: useCallback(161 params => {162 return auth.get(`/search/filters`, { params })163 },164 [auth],165 ),166 editArticle: useCallback(167 articleInfo => {168 return auth.put('/articles', articleInfo)169 },170 [auth],171 ),172 getArticle: useCallback(173 ({ articleId, params }) => {174 return instance.get(`/articles${articleId ? `/${articleId}` : ''}`, {175 params,176 })177 },178 [instance],179 ),180 getTradingAtricles: useCallback(181 params => {182 return auth.get('/articles?tradeStatusCode=4', { params })183 },184 [auth],185 ),186 getArticleOfCategory: useCallback(187 ({ categoryCode, params }) => {188 return instance.get(`/articles?categoryCode=${categoryCode}`, {189 params,190 })191 },192 [instance],193 ),194 getOffersList: useCallback(195 articleId => {196 return auth.get(`/articles/${articleId}/offers`)197 },198 [auth],199 ),200 getOfferListPage: useCallback(201 ({ articleId, params }) => {202 return auth.get(`/articles/${articleId}/offers`, { params })203 },204 [auth],205 ),206 getImgUrlList: useCallback(207 articleId => {208 return instance.get(`/articles/${articleId}/imageUrls`)209 },210 [instance],211 ),212 changeTradeStatus: useCallback(213 ({ articleId, option }) => {214 return auth.patch(`/articles/${articleId}/tradeStatus`, option)215 },216 [auth],217 ),218 deleteArticle: useCallback(219 articleId => {220 return auth.delete(`/articles/${articleId}`)221 },222 [auth],223 ),224 toggleLikeArticle: useCallback(225 articleId => {226 return auth.put(`/articles/${articleId}/like`)227 },228 [auth],229 ),230 postOffer: useCallback(231 ({ articleId, price }) => {232 return auth.post(`/articles/${articleId}/offers`, price)233 },234 [auth],235 ),236 selectOffer: useCallback(237 offerId => {238 return auth.patch(`/articles/offers/${offerId}`)239 },240 [auth],241 ),242 getArticleUserID: useCallback(243 articleId => {244 return auth.get(`/articles/${articleId}`)245 },246 [auth],247 ),248 getArticlesInfos: useCallback(() => {249 return instance.get('articles/infos')250 }, [instance]),251 }252 const messageApi = {253 postMessageToOffer: useCallback(254 ({ memberId, offerId, articleId, content }) => {255 return auth.post(256 `/messages/member/${memberId}/offerId/${offerId}?articleId=${articleId}`,257 content,258 )259 },260 [auth],261 ),262 postMessage: useCallback(263 ({ messageRoomId, message }) => {264 return auth.post(`/messages/messageRoom/${messageRoomId}`, message)265 },266 [auth],267 ),268 getMessageList: useCallback(269 ({ messageRoomId, params }) => {270 return auth.get(`/messages/messageRoom/${messageRoomId}/contents`, {271 params,272 })273 },274 [auth],275 ),276 getMessageRoomInfo: useCallback(277 ({ messageRoomId }) => {278 return auth.get(279 `/messages/messageRoom/${messageRoomId}/messageRoomInfo`,280 )281 },282 [auth],283 ),284 deleteMessageBox: useCallback(285 ({ messageRoomId }) => {286 return auth.delete(` /messages/messageRoomId/${messageRoomId}`)287 },288 [auth],289 ),290 getMessageBox: useCallback(() => {291 return auth.get('/messages/messageBox')292 }, [auth]),293 }294 const imgApi = {295 convertImgList: useCallback(296 images => {297 return instance.post('/articles/imageUrls', images)298 },299 [instance],300 ),301 convertImg: useCallback(302 image => {303 return instance.post('/members/imageUrls', image)304 },305 [instance],306 ),307 }308 return { authApi, userApi, reviewApi, articleApi, messageApi, imgApi }309}...
Stammdaten.js
Source:Stammdaten.js
...39 const location = store.location.toJSON()40 const activeLocation = location[0]41 const { table, id, rows, fetch } = store.table42 const tableName = table ? tableNameObject[table] || table : ''43 const fetchAbteilungen = useCallback(() => fetch('abteilung'), [fetch])44 const fetchInterne = useCallback(() => fetch('interne'), [fetch])45 const fetchExterne = useCallback(() => fetch('externe'), [fetch])46 const fetchAktenstandort = useCallback(() => fetch('aktenstandort'), [fetch])47 const fetchGeschaeftsart = useCallback(() => fetch('geschaeftsart'), [fetch])48 const fetchParlVorstossTyp = useCallback(() => fetch('parlVorstossTyp'), [49 fetch,50 ])51 const fetchRechtsmittelInstanz = useCallback(52 () => fetch('rechtsmittelInstanz'),53 [fetch],54 )55 const fetchRechtsmittelErledigung = useCallback(56 () => fetch('rechtsmittelErledigung'),57 [fetch],58 )59 const fetchStatus = useCallback(() => fetch('status'), [fetch])60 const onClickInsert = useCallback(() => rows.insert(table), [rows, table])61 const onClickDelete = useCallback(() => rows.delete(table, id), [62 id,63 rows,64 table,65 ])66 const isActive = activeLocation === 'table'67 return (68 <StamdatenContainer active={isActive}>69 <UncontrolledDropdown nav inNavbar active={isActive}>70 <DropdownToggle nav caret>71 {table ? (72 <span>73 {tableName}74 <Sup>{table ? rows[table].length : 0}</Sup>75 </span>...
buff.js
Source:buff.js
...6}7Buff.prototype.use = function(player) {8 if (!!this.useCallback) {9 player.addBuff(this);10 this.useCallback(player);11 if (this.timeout > 0){12 if (!!this.unuseCallback) {13 setTimeout(function(){14 player.removeBuff(this);15 this.unuseCallback(player);16 }, this.timeout);17 }18 }19 }20};21var ConfuseBuff = (function() {22 return function(timeout) {23 return new Buff({24 type: 'confuse',25 useCallback: function(player){26 player.confused = true;27 },28 unuseCallback: function(player){29 player.confused = false;...
useAuth.js
Source:useAuth.js
...3import * as authActions from '../store/actions';4const useAuth = (getKey = null) => {5 const data = useSelector((state) => state.auth);6 const dispatch = useDispatch();7 const hasPermission = useCallback(8 (permission) => data.permissions.includes(permission),9 [data]10 );11 const login = useCallback((params) => dispatch(authActions.login(params)), [12 dispatch13 ]);14 const refresh = useCallback(15 (params) => dispatch(authActions.refreshToken(params)),16 [dispatch]17 );18 const changeLogin = useCallback(19 (params) => dispatch(authActions.changeLogin(params)),20 [dispatch]21 );22 const logout = useCallback(() => dispatch(authActions.logout()), [dispatch]);23 const isAuthenticated = useMemo(24 () =>25 !!(26 data.expirationDate &&27 data.expirationDate > new Date() &&28 data.accessToken29 ),30 [data.expirationDate, data.accessToken]31 );32 const getClaim = useCallback(33 (type) => data.claims.find((c) => c.type === type),34 [data]35 );36 const getClaims = useCallback(37 (type) => data.claims.filter((c) => c.type === type),38 [data]39 );40 const hasClaim = useCallback(41 (type) => data.claims.findIndex((c) => c.type === type) >= 0,42 [data]43 );44 const hasRole = useCallback((...roles) => roles.includes(data.user.role), [45 data46 ]);47 const isAdmin = () => {48 return data.user && data.user.role === 'Admin';49 };50 let key = null;51 try {52 key = getKey ? getKey(data) : data.user.id;53 } catch (error) {54 key = 'auth.provider';55 }56 return {57 ...data,58 key,...
index.js
Source:index.js
1import { useRef, useEffect, useCallback } from 'react'2const useTimingEvents = () => {3 const timeoutRefs = useRef({})4 const intervalRefs = useRef({})5 const addTimeout = useCallback((timeout, key) => {6 timeoutRefs.current[key || timeout] = timeout7 return timeout8 }, [])9 const addInterval = useCallback((interval, key) => {10 intervalRefs.current[key || interval] = interval11 return interval12 }, [])13 const getTimeout = useCallback((key) => {14 return timeoutRefs.current[key]15 }, [])16 const getInterval = useCallback((key) => {17 return intervalRefs.current[key]18 }, [])19 const clearTimeout = useCallback((key) => {20 window.clearTimeout(getTimeout(key) || key)21 delete timeoutRefs.current[key]22 }, [])23 const clearInterval = useCallback((key) => {24 window.clearInterval(getInterval(key) || key)25 delete intervalRefs.current[key]26 }, [])27 const clearAllTimeout = useCallback(() => {28 Object.keys(timeoutRefs.current).forEach(key => {29 clearTimeout(key)30 })31 timeoutRefs.current = {}32 }, [])33 const clearAllInterval = useCallback(() => {34 Object.keys(intervalRefs.current).forEach(key => {35 clearInterval(key)36 })37 intervalRefs.current = {}38 }, [])39 useEffect(() => {40 return () => {41 clearAllTimeout()42 clearAllInterval()43 }44 }, [])45 return {46 addTimeout,47 addInterval,...
callback.js
Source:callback.js
...7 * 1.é¿å
ç»ä»¶çéå¤æ¸²æ8 *9 * useMemo useCallback10 * åæ ·ç¨å°çæ¯ç¼åææ¯ï¼ useCallback ç¼åçæ¯ä¸ä¸ªå½æ°ï¼å½æ°å¯ä»¥æ§è¡11 * useCallback(fnï¼[å¯ä»¥ä¸å])12 *13 *14 */15import React, {useState,useCallback} from 'react';1617const Callback = () => {18 const [count, setCount] = useState(100);19 let callback = useCallback(() => {20 console.log('useCallback');21 console.log(count)22 return count;2324 },[]);25 return (26 <div>27 <h1>useCallback</h1>28 <p>{count}</p>29 <p>è¿åçå¼ï¼{callback()}</p>30 <button31 onClick={() => {32 setCount((c) => c + 20)33 }}
...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.click('text=Docs');7 await page.click('text=API');8 await page.click('text=class: BrowserContext');9 console.log(page.url());10 await context.close();11 await browser.close();12})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const search = await page.$('input[name="q"]');7 await search.type('Playwright');8 await search.press('Enter');9 await page.waitForSelector('text="Playwright"');10 await page.screenshot({ path: 'google-playwright.png' });11 await browser.close();12})();13const { chromium } = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 const search = await page.$('input[name="q"]');19 await search.type('Playwright');20 await search.press('Enter');21 await page.waitForFunction(() => !!document.querySelector('text="Playwright"'));22 await page.screenshot({ path: 'google-playwright.png' });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 const search = await page.$('input[name="q"]');31 await search.type('Playwright');32 await search.press('Enter');33 await page.waitForSelector('text="Playwright"');34 await page.screenshot({ path: 'google-playwright.png' });35 await browser.close();36})();37const { chromium } = require('playwright');38(async () => {39 const browser = await chromium.launch();40 const context = await browser.newContext();41 const page = await context.newPage();42 const search = await page.$('input[name="q"]');43 await search.type('Playwright');44 await search.press('Enter');45 await page.waitForTimeout(3000);46 await page.screenshot({ path: 'google-play
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 const input = await page.$('input');7 await input.type('Hello');8 await page.screenshot({ path: `example.png` });9 await browser.close();10})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const page = await browser.newPage();5 await page.screenshot({ path: `example.png` });6 await browser.close();7})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({4 });5 const page = await browser.newPage();6 await page.screenshot({ path: 'google.png' });7 await browser.close();8})();
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const page = await browser.newPage();5 await page.click('input[aria-label="Search"]');6 await page.fill('input[aria-label="Search"]', 'Playwright');7 await page.keyboard.press('Enter');8 await page.click('text=Playwright - Google Search');9 await page.click('text=Docs');10 await page.click('text=API');11 await page.click('text=Page');12 await page.click('text=page.click');13 await page.click(
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.screenshot({ path: `example.png` });6 await browser.close();7})();8const { chromium } = require('playwright');9(async () => {10 const browser = await chromium.launch();11 const page = await browser.newPage();12 const title = await page.evaluate(() => document.title);13 console.log('title:', title);14 await browser.close();15})();16const { chromium } = require('playwright');17(async () => {18 const browser = await chromium.launch();19 const page = await browser.newPage();20 const title = await page.evaluate(() => document.title);21 console.log('title:', title);22 await browser.close();23})();24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();27 const page = await browser.newPage();28 const title = await page.evaluate(() => document.title);29 console.log('title:', title);30 await browser.close();31})();32const { chromium } = require('playwright');33(async () => {34 const browser = await chromium.launch();35 const page = await browser.newPage();36 const title = await page.evaluate(() => document.title);37 console.log('title:', title);38 await browser.close();39})();40const { chromium } = require('playwright');41(async () => {42 const browser = await chromium.launch();43 const page = await browser.newPage();44 const title = await page.evaluate(() => document.title);45 console.log('title:', title);46 await browser.close();47})();48const { chromium } = require('playwright');49(async () => {
Using AI Code Generation
1const { chromium } = require('playwright');2const { test, expect } = require('@playwright/test');3test('test', async ({ page }) => {4 const title = page.locator('.navbar__inner .navbar__title');5 await expect(title).toHaveText('Playwright');6});7const { chromium } = require('playwright');8const { test, expect } = require('@playwright/test');9test('test', async ({ page }) => {10 await page.waitForSelector('.navbar__inner .navbar__title');11 const title = page.locator('.navbar__inner .navbar__title');12 await expect(title).toHaveText('Playwright');13});14const { chromium } = require('playwright');15const { test, expect } = require('@playwright/test');16test('test', async ({ page }) => {17 const link = page.locator('text=Docs');18 await link.click();19 await page.waitForNavigation();20 const title = page.locator('text=Playwright API');21 await expect(title).toBeVisible();22});23const { chromium } = require('playwright');24const { test, expect } = require('@playwright/test');25test('test', async ({ page }) => {26 await page.waitForTimeout(5000);27 const title = page.locator('.navbar__inner .navbar__title');28 await expect(title).toHaveText('Playwright');29});30const { chromium } = require('playwright');31const { test, expect } = require('@playwright/test');32test('test', async ({ page }) => {33 await page.screenshot({ path: 'example.png' });34 const title = page.locator('.navbar__inner .navbar__title');35 await expect(title).toHaveText('Playwright');36});37const { chromium } = require('playwright');38const { test, expect } = require('@playwright/test
Using AI Code Generation
1const { chromium } = require('playwright');2const { test, expect } = require('@playwright/test');3test('test', async ({ page }) => {4 await page.goto(url);5 await page.waitForSelector('input[name="q"]');6 await page.type('input[name="q"]', 'Hello World');7 await page.keyboard.press('Enter');8 await page.waitForSelector('h3');9 await page.screenshot({ path: `screenshot.png` });10 const title = await page.title();11 expect(title).toBe('Hello World - Google Search');12});
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2const { chromium } = require('playwright');3test('Test', async ({ page }) => {4 await page.click('text="Get started"');5 await page.click('text="Docs"');6 await page.click('text="API"');7 await page.click('text="class: Page"');8 await page.click('text="page.goto"');9 await page.click('text="page.route"');10 await page.click('text="page.screenshot"');11 await page.click('text="page.waitForSelector"');12 await page.click('text="page.waitForTimeout"');13 await page.click('text="page.waitForURL"');14 await page.click('text="page.waitForLoadState"');15 await page.click('text="page.waitForEvent"');16 await page.click('text="page.waitForFunction"');17 await page.click('text="page.waitForRequest"');18 await page.click('text="page.waitForResponse"');19 await page.click('text="page.$"');20 await page.click('text="page.$$"');21 await page.click('text="page.$eval"');22 await page.click('text="page.$$eval"');23 await page.click('text="page.$x"');24 await page.click('text="page.evaluate"');25 await page.click('text="page.evaluateHandle"');26 await page.click('text="page.exposeBinding"');27 await page.click('text="page.exposeFunction"');28 await page.click('text="page.frames"');29 await page.click('text="page.mainFrame"');30 await page.click('text="page.frame"');31 await page.click('text="page.childFrames"');32 await page.click('text="page.$eval"');33 await page.click('text="page.$$eval"');34 await page.click('text="page.$x"');35 await page.click('text="page.evaluate"');36 await page.click('text="page.evaluateHandle"');37 await page.click('text="page.exposeBinding"');
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!