Skip to content

Instantly share code, notes, and snippets.

const withAcknowledgement = (socketFunc) => (...args) => new Promise((resolve, reject) => {
let state = 'pending'; // eslint-disable-line
const timer = setTimeout(() => {
state = 'rejected';
reject();
}, 3000);
socketFunc(...args, (response) => {
if (state !== 'pending') return;
@MrMeison
MrMeison / auth
Created September 14, 2022 16:17
// Auth провайдер, обертка для прокидывания информации о пользователе
const AuthProvider = ({ children }) => {
const currentUser = JSON.parse(localStorage.getItem('user'));
const [user, setUser] = useState(currentUser ? { username: currentUser.username } : null);
const logIn = (userData) => {
localStorage.setItem('user', JSON.stringify(userData));
setUser({ username: userData.username });
};
const Map = (props: PropsMap) => {
...
useEffect(() => {
if (!map) {
return;
}
const layerGroup = new LayerGroup();
points.forEach((point) => {
@MrMeison
MrMeison / useMap.tsx
Created August 1, 2022 11:24
leaflet useMap
import {useEffect, useState, MutableRefObject} from 'react';
import {Map, TileLayer} from 'leaflet';
import {City} from '../types/city';
function useMap(
mapRef: MutableRefObject<HTMLElement | null>,
city: City
): Map | null {
const [map, setMap] = useState<Map | null>(null);
export const useVideo = (videoRef: RefObject<HTMLVideoElement>, device: MediaDeviceInfo) => {
const [started, setStarted] = useState(false);
useEffect(() => {
if (!videoRef.current || !device) {
return noop;
}
const videoService = new VideoService();
const start = async () => {
const { useEffect, useRef } = require("react");
const noop = () => {};
class Editor {
constructor(element) {
this.element = element;
}
destroy() {
var simpleObject = {
property: 4,
method: function () {
console.log(this.property);
}
};
var simpleFunction = function() {
this.property = 5;
(function() {
// 1 вариант: выхов от результата. Пример задача на суммирование.
const fn = (...args) => {
const wrapper = () => {
return fn;
}
return wrapper;
}
console.log(fn()()()());
{
"id": "42",
"author": "Ilya O'Reilly",
"comment": "a film that changed my life, a true masterpiece, post-credit scene was just amazing omg.",
"date": "2019-05-11T16:12:32.554Z",
"emotion": "neutral-face"
}
{
"id": "0",
"comments": [
$Comment.id$, $Comment.id$
],
"film_info": {
"title": "A Little Pony Without The Carpet",
"alternative_title": "Laziness Who Sold Themselves",
"total_rating": 5.3,
"poster": "images/posters/blue-blazes.jpg",