05 2020 档案
摘要:def my_decorator(func): def wrapper(): print("Something is happening before the function is called.") func() print("Something is happening after the f
阅读全文
摘要:The same as Javascript: // Javascript function sayHello(name) { return `Hello ${name}` } //python def say_hello(name): return f"Hello {name}"
阅读全文
摘要:class Clothing: def __init__(self, color, size, style, price): self.color = color self.size = size self.style = style self.price = price def change_pr
阅读全文
摘要:Mirage JS lets you mock out production APIs directly alongside your frontend React code. You can tweak the data or force a network request to hang, so
阅读全文
摘要:Let's say we have following semigroups: // Total: Sum up all the number const Total = (x) => ({ x, concat(o) { return Total(o.x + x); }, fold() { retu
阅读全文
摘要:It can be difficult to work on multiple projects that use different versions of Node. nvm (Node Version Manger) make this easier by allowing you to do
阅读全文
摘要:Thinking how to add tow Guessin object together? It is similar idea to Functional programming, Data type. import math import matplotlib.pyplot as plt
阅读全文
摘要:import math import matplotlib.pyplot as plt class Gaussian(): """ Gaussian distribution class for calculating and visualizing a Gaussian distribution.
阅读全文
摘要:For example, we have current html code: <main class="grid-wrap"> <div class="grid"> <span>One column default</span> </div> <div class="grid"> <span>Ha
阅读全文
摘要:Now that we know what we are looking for, let's go over some tips on how to actually write your code review. When your coworker finishes up some code
阅读全文
摘要:Is the code clean and modular? Can I understand the code easily? Does it use meaningful names and whitespace? Is there duplicated code? Can you provid
阅读全文
摘要:import time import pandas as pd import numpy as np with open('books_published_last_two_years.txt') as f: recent_books = f.read().split('\n') with open
阅读全文
摘要:const Task = require("data.task"); const Either = require("data.either"); const { Right, Left } = Either; const { List } = require("immutable-ext"); c
阅读全文
摘要:const Task = require("data.task"); const Either = require("data.either"); const { Right, Left } = Either; const { List } = require("immutable-ext"); /
阅读全文
摘要:Long time ago, frontend developers (or as we called them back then - webmasters) could get away with supporting only one or two resolutions. Those day
阅读全文
摘要:Manage the color palette used in your stylesheets by creating a map of variables and a function to access the values by key. This allows you to update
阅读全文
摘要:When we need to spin up a database instance for our new project, installing the database management system directly on our local machine is almost alw
阅读全文
摘要:const { merge, timer, Subject, combineLatest } = require("rxjs"); const { tap, mapTo, skip, filter, startWith, takeUntil, switchMap, } = require("rxjs
阅读全文
摘要:const useResetScore = () => { const [score, setScore] = useRecoilState(gameScore) return () => { setScore(0) } } ... const resetScore = useResetScore(
阅读全文
摘要:Recoil allows us to use atoms in order to store pieces of state. More often than not in our apps we need to use data that derives from our application
阅读全文
摘要:Recoil is a brand new state management library for React developed by Facebook. In this quick lesson we're going to learn how to add it to a React app
阅读全文
摘要:In this lesson, we build a little app that fetches dog photos from the dog.ceo API, based on a "breed" search field. We want the API call to happen ag
阅读全文
摘要:In this lesson, we learn how the x-init directive in Alpine JS lets us run a JavaScript expression once the component has initiated. We see the nuance
阅读全文
摘要:In this lesson, we learn how to retrieve a DOM element via the x-ref directive in Alpine JS, which gives us a reference to the element it is applied o
阅读全文
摘要:In this lesson, we see how the x-model directive makes achieving "two-way data binding" effortless in Alpine JS. We see what it would take to recreate
阅读全文
摘要:In this lesson, we smoothen the transitions between tabs by applying a transition modifier to our x-show directive. We see how we can ignore the leavi
阅读全文
摘要:In this lesson, we move the component definition to a function, defined in a script tag in the HTML document. We then iterate through an Array of Obje
阅读全文
摘要:In this lesson, we create a set of tabs with Alpine JS, where only the content of the currently active tab is visible. To do this, we define an active
阅读全文
摘要:In this lesson, we define a "count" state value with the x-data directive provided by Alpine JS. This defines a new scoped component, which can have a
阅读全文
摘要:Using the open function, and the as and with keywords, we'll open up and read from a file. At the end of this lesson, you will be able to loop through
阅读全文
摘要:Let's see the following code first: let button = document.getElementById("button"); button.addEventListener("click", (e) => { console.log(e) }); We ha
阅读全文
摘要:Folder structure: | __mocks__ | api | pet.js | src | api | pet.js __mocks__/api/pet.js // __mocks__/api/pet.js import { readFileSync } from 'fs' impor
阅读全文
摘要:object-position controls the placement of img and video media inside containing boxes. It's a partner property to object-fit. Using the two properties
阅读全文
摘要:When you or your team work on various npm or yarn projects it gets hard to remember which one is which. This lesson shows you how to create a custom n
阅读全文
摘要:const Box = x => ({ map: f => Box(f(x)), chain: f => f(x), fold: f => f(x), toString: () => `Box(${x})` }) // Exercise: Box // Goal: Refactor each exa
阅读全文
摘要:As a beginner of React, might have the confuses with 'useMemo' and 'React.memo': 'useMemo': When using functional components in React we may run into
阅读全文
该文被密码保护。
摘要:For development, we'll be using a separate server address to reach our REST endpoints. In a production build, this will likely be a different address,
阅读全文
摘要:In package.json file: "prepare": "npm run build", "postpublish": "git push --tags", "prepare": make sure we don't forget to run build before publish t
阅读全文
摘要:It's always important to test your code, especially if you're open-sourcing it for others to use. In this video, we'll learn how to use react-hooks-te
阅读全文
摘要:When you use a React Portal, much of your component can be rendered outside the main DOM tree. Let’s see how we can use utilities provided by React Te
阅读全文
摘要:You can get a huge amount of confidence and coverage from integration tests that test an entire page, or even your entire app. Let’s write a test that
阅读全文
摘要:Sometimes your react component may need to do some cleanup work in the return value from useEffect or useLayoutEffect, or the componentWillUnmount lif
阅读全文
摘要:That setup function is pretty handy. Seems like a good opportunity for an abstraction. Well, we already have one! It’s called React Hooks Testing Libr
阅读全文
摘要:It’s very common for our components to use state from the redux store (or to be refactored to use it eventually). Having to change our tests every tim
阅读全文
摘要:We’ve got a custom useCounter hook here and we want to make sure the increment and decrement functions it returns will update the count state that it
阅读全文
摘要:Mocking the <Redirect /> component in react-router works, but it’s imperfect because we don’t know for sure that the user will be redirected properly.
阅读全文
摘要:We have the happy path covered for our post editor component, but what happens if there’s an error in saving the user’s information? We should probabl
阅读全文
摘要:A really important aspect of TDD is the refactor phase. A critical piece to making your tests easier to maintain is using code structure and values to
阅读全文
摘要:Just make sure the date is in a range then it is fine import React from 'react' import {render, fireEvent, waitFor} from '@testing-library/react' impo
阅读全文
摘要:Once the data has been saved on the server, we’ll want to redirect the user to the home screen with react-router’s <Redirect /> component. Let’s go ah
阅读全文
摘要:We have a bit of repetition in our rerender calls here and it would be nice if we could avoid that. Let’s use the wrapper option for React Testing Lib
阅读全文
摘要:Our error boundary has some other use cases that it supports and we should try to make sure our tests cover all those use cases, so let’s add a test t
阅读全文
摘要:When testing an error boundary, your console will be filled with console.error calls from React. Those can be a real distraction from the rest of the
阅读全文
摘要:Error boundary: import React from 'react' import { reportError } from './components/extra/api' export default class ErrorBoundary extends React.Compon
阅读全文
摘要:There are some situations where you want to focus your tests on a particular component and not any of its children. There are other situations where y
阅读全文