const moveQueue = {
queue: [],
index: 0,
create() {
let endMoveCallback;
// создаём висячий промис и присваиваем его разрешение в endMoveCallback
const movePending = new Promise(resolve => endMoveCallback = resolve);
// index чисто для лога
endMoveCallback.index = this.index++;
// добавляем в очередь
this.queue.push(endMoveCallback);
// возвращаем проис ждущий вызова endMoveCallback
return movePending;
},
last() {
// забираем из очереди последнее добавленное
return this.queue.pop();
}
}
async function turn() {
await startMove();
await startShoot();
}
function startMove() {
console.log('startMove', moveQueue.index);
return moveQueue.create();
}
function endMove() {
const activeMoveEnd = moveQueue.last();
if (activeMoveEnd) {
console.log('endMove', activeMoveEnd.index)
activeMoveEnd();
} else {
onsole.error('`endMove` called when there are no active moves')
}
}
function startShoot() {
console.log('startShoot');
}
turn();
setTimeout(() => endMove(), 1000)
live-server
это не "стандартный сервер", это сторонний софт, причём мёртвый несмотря на название. Живой на данный момент форк - alive-server
. Но проблема, если что, не в этом.:) const thumbs = reactive([null, null, null]);
v-for="(swiper, i) in thumbs" @swiper="thumbs[i]=$event" :thumbs="{ swiper }"
function escapeRegExp(string) {
return String(string).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
// для оптимизации неплохо бы завернуть в memoize-one
const toSpacedRegExp = (needle, ignoreCase = true) => new RegExp(
needle
.trim()
.split(/\s+/)
.map(chunk => '(' + escapeRegExp(chunk) + ')')
.join('(\\S*(?:\\s+\\S*)+?)'),
ignoreCase ? 'i' : ''
);
// для оптимизации неплохо бы завернуть в memoize-one
const toSomeRegExp = (needle, ignoreCase = true) => new RegExp(
needle
.trim()
.split(/\s+/)
.map(chunk => '(' + escapeRegExp(chunk) + ')')
.join('([\\S\\s]*)'),
ignoreCase ? 'i' : ''
);
// Возвращает либо false, либо массив разделённых совпадний
// smartFind('start found rest', 'found') // ['start ', 'found', ' rest']
// smartFind('start found rest', 'start') // ['', 'start', ' found rest']
// удобно для подсвечивания найденного тупо через i % 2
function smartFind(haystack, needle) {
if (!haystack) return false;
if (!needle) return ['', haystack, ''];
// ищем сначала разделённые пробелами: ва ся => ВАся СЯпкин
let result = haystack.split(toSpacedRegExp(needle));
if (result.length > 1) return result;
// ищем хоть какое-то совпадение: ва ся => ВАСЯ пупкин
result = haystack.split(toSomeRegExp(needle));
return result.length > 1 && result;
}
http
(хз что за сайт, нагуглен из списка "popular websites loaded insecurely") , прекрасно грузит иконку сверху слева.image/<что-то>
идёт какая-то ересь и браузер решает попытать счастья на https
. Тогда надо поправить MIME types
на сервере.https
с включенным HSTS
. Тогда надо руками удалить из браузера сохранённую метку.<Row justify="space-around">
<Col flex="none">
...
</Col>
<Col flex="none">
...
</Col>
</Row>
<Row>
<Col span={12}>
<Row justify="center">
<Col flex="none">
...
</Col>
</Row>
</Col>
<Col span={12}>
<Row justify="center">
<Col flex="none">
...
</Col>
</Row>
</Col>
</Row>
class CompatibleBounds {
northEast = [0, 0];
southWest = [0, 0];
constructor(bounds) {
Object.assign(this, bounds);
}
static new(bounds) {
return new this(bounds);
}
get south(){ return this.southWest[1] }
get west(){ return this.southWest[0] }
get north(){ return this.northEast[1] }
get east(){ return this.northEast[0] }
set south(value){ this.southWest[1] = value }
set west(value){ this.southWest[0] = value }
set north(value){ this.northEast[1] = value }
set east(value){ this.northEast[0] = value }
}
const compatibleBounds = CompatibleBounds.new({
"south": 43.106491921792255,
"west": 76.71745650634767,
"north": 43.4065384633472,
"east": 77.13974349365236
});
// или
const compatibleBounds = CompatibleBounds.new({
"northEast": [
76.92894332280319,
43.25695003829279
],
"southWest": [
76.92825667730312,
43.256449960663694
]
});
// на выходе универсальный динамический объект:
compatibleBounds.southWest = [1, 2];
console.log(compatibleBounds.south); // 2
compatibleBounds.south = 3
console.log(compatibleBounds.southWest); // [1, 3]
const ThemeProvider: FC = ...;
ThemeProvider
имеет тип FC
, и пофиг что ты там дальше пишешь. Тип FC
по умолчанию не имеет children
.const ThemeProvider: FC<{children: ...}> = ...;
const ThemeProvider = ({ children }: ...) => ...;
props
, children
это поле props
, а не верхний аргумент.const ThemeProvider: FC<PropsWithChildren> = ...
PropsWithChildren
- тип помощник, добавляющий children
к объекту, например PropsWithChildren<{
prop2: string;
prop3: number
}>
но без дженерика просто отдаёт тип вида {
children?: ReactNode | undefined;
}
type Lettrer = 'a' | 'b' | ...
type Digit = 1 | 2 | ...
...
string
и просто number
.type ZipCode = string;
type GeoCoord = number;
transformAssetUrls
. Однако открыв доки я вижу там: Converts src to provider optimized URLs
import img from '~/assets/images/header.jpg'
?