Last major update: 25.08.2020
- Что такое авторизация/аутентификация
- Где хранить токены
- Как ставить куки ?
- Процесс логина
- Процесс рефреш токенов
- Кража токенов/Механизм контроля токенов
// We want to subscribe to some data. Here are 2 ways to do the SAME thing. | |
// 1. setup some state | |
// 2. subscribing to a uid, set posts when they come in | |
// 3. unsubscribing when the component unmounts | |
// 4. when the uid changes: | |
// - unsubscribing from prev uid | |
// - re-subscribing to the new uid | |
// Here's a render prop: |
import * as actions from 'action-creators'; | |
// Тип, который берет action-creators, выводит типы всех экшенов по отдельности и собирает их в union | |
type InferValueTypes<T> = T extends { [key: string]: infer U } | |
? U | |
: never; | |
type ActionTypes = ReturnType<InferValueTypes<typeof actions>>; |
import { useRef, useState } from 'react' | |
function useUndo([state, setState]) { | |
const history = useRef([state]) | |
const [index, setIndex] = useState(0) | |
function undo() { | |
setIndex(Math.max(index - 1, 0)) | |
} | |
function redo() { |
import { useEffect, useRef } from 'react'; | |
function getItem(storage, key) { | |
const value = storage.getItem(key); | |
if (!value) return null; | |
try { | |
return JSON.parse(value); | |
} catch (error) { |
const EventEmitter = require("events").EventEmitter; | |
class Pizza extends EventEmitter { | |
constructor(size = 1) { | |
super(); | |
this.ovenTime = this._ovenTime(size); | |
this.maxIngredients = this._maxIngredients(size); | |
this.ingredients = []; | |
this.timeToReleasePizza = 5; | |
} |
import React from 'react' | |
/** | |
* @typedef {object} State The state of asynchronous hooks. | |
* @property {object | null} error The error. | |
* @property {boolean} pending Whether the call is pending. | |
* @property {any | null} result The result of the asynchronous call. | |
*/ | |
/** @type {State} */ |
FWIW: I (@rondy) am not the creator of the content shared here, which is an excerpt from Edmond Lau's book. I simply copied and pasted it from another location and saved it as a personal note, before it gained popularity on news.ycombinator.com. Unfortunately, I cannot recall the exact origin of the original source, nor was I able to find the author's name, so I am can't provide the appropriate credits.
Answer: All APIs of Node.js library are aynchronous that is non-blocking. It essentially means a Node.js based server never waits for a API to return data. Server moves to next API after calling it and a notification mechanism of Events of Node.js helps server to get response from the previous API call.
Source: tutorialspoint.com
Just migrated it from Codepen.io to markdown. Credit goes to David Conner.
Working with DOM | Working with JS | Working With Functions |
---|---|---|
Accessing Dom Elements | Add/Remove Array Item | Add Default Arguments to Function |
Grab Children/Parent Node(s) | Add/Remove Object Properties | Throttle/Debounce Functions |
Create DOM Elements | Conditionals |