@lvce-editor/running-extensions-view 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1388,6 +1388,7 @@ const toCommandId = key => {
|
|
|
1388
1388
|
return key.slice(dotIndex + 1);
|
|
1389
1389
|
};
|
|
1390
1390
|
const create$1 = () => {
|
|
1391
|
+
const commandQueues = new Map();
|
|
1391
1392
|
const generations = Object.create(null);
|
|
1392
1393
|
const states = Object.create(null);
|
|
1393
1394
|
const commandMapRef = {};
|
|
@@ -1410,8 +1411,44 @@ const create$1 = () => {
|
|
|
1410
1411
|
}
|
|
1411
1412
|
return Promise.resolve(updatedState);
|
|
1412
1413
|
};
|
|
1414
|
+
const createAsyncCommandContext = (uid, generation) => {
|
|
1415
|
+
let latestState = states[uid].newState;
|
|
1416
|
+
return {
|
|
1417
|
+
getState: () => {
|
|
1418
|
+
if (isCurrentGeneration(uid, generation)) {
|
|
1419
|
+
latestState = states[uid].newState;
|
|
1420
|
+
}
|
|
1421
|
+
return latestState;
|
|
1422
|
+
},
|
|
1423
|
+
updateState: async updater => {
|
|
1424
|
+
latestState = await updateState(uid, generation, latestState, updater);
|
|
1425
|
+
return latestState;
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
};
|
|
1429
|
+
const enqueueCommand = async (uid, command) => {
|
|
1430
|
+
const previous = commandQueues.get(uid) || Promise.resolve();
|
|
1431
|
+
const run = async () => {
|
|
1432
|
+
try {
|
|
1433
|
+
await previous;
|
|
1434
|
+
} catch {
|
|
1435
|
+
// The previous caller receives its error; later commands must still run.
|
|
1436
|
+
}
|
|
1437
|
+
await command();
|
|
1438
|
+
};
|
|
1439
|
+
const current = run();
|
|
1440
|
+
commandQueues.set(uid, current);
|
|
1441
|
+
try {
|
|
1442
|
+
await current;
|
|
1443
|
+
} finally {
|
|
1444
|
+
if (commandQueues.get(uid) === current) {
|
|
1445
|
+
commandQueues.delete(uid);
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
};
|
|
1413
1449
|
return {
|
|
1414
1450
|
clear() {
|
|
1451
|
+
commandQueues.clear();
|
|
1415
1452
|
for (const key of Object.keys(states)) {
|
|
1416
1453
|
delete states[key];
|
|
1417
1454
|
}
|
|
@@ -1431,6 +1468,7 @@ const create$1 = () => {
|
|
|
1431
1468
|
return diffResult;
|
|
1432
1469
|
},
|
|
1433
1470
|
dispose(uid) {
|
|
1471
|
+
commandQueues.delete(uid);
|
|
1434
1472
|
delete states[uid];
|
|
1435
1473
|
},
|
|
1436
1474
|
get(uid) {
|
|
@@ -1461,19 +1499,7 @@ const create$1 = () => {
|
|
|
1461
1499
|
wrapAsyncCommand(fn) {
|
|
1462
1500
|
const wrapped = async (uid, ...args) => {
|
|
1463
1501
|
const generation = getGeneration(uid);
|
|
1464
|
-
|
|
1465
|
-
const context = {
|
|
1466
|
-
getState: () => {
|
|
1467
|
-
if (isCurrentGeneration(uid, generation)) {
|
|
1468
|
-
latestState = states[uid].newState;
|
|
1469
|
-
}
|
|
1470
|
-
return latestState;
|
|
1471
|
-
},
|
|
1472
|
-
updateState: async updater => {
|
|
1473
|
-
latestState = await updateState(uid, generation, latestState, updater);
|
|
1474
|
-
return latestState;
|
|
1475
|
-
}
|
|
1476
|
-
};
|
|
1502
|
+
const context = createAsyncCommandContext(uid, generation);
|
|
1477
1503
|
await fn(context, ...args);
|
|
1478
1504
|
};
|
|
1479
1505
|
return wrapped;
|
|
@@ -1551,6 +1577,51 @@ const create$1 = () => {
|
|
|
1551
1577
|
};
|
|
1552
1578
|
};
|
|
1553
1579
|
return wrapped;
|
|
1580
|
+
},
|
|
1581
|
+
wrapSerialAsyncCommand(fn) {
|
|
1582
|
+
const wrapped = async (uid, ...args) => {
|
|
1583
|
+
await enqueueCommand(uid, async () => {
|
|
1584
|
+
if (!states[uid]) {
|
|
1585
|
+
return;
|
|
1586
|
+
}
|
|
1587
|
+
const generation = getGeneration(uid);
|
|
1588
|
+
const context = createAsyncCommandContext(uid, generation);
|
|
1589
|
+
await fn(context, ...args);
|
|
1590
|
+
});
|
|
1591
|
+
};
|
|
1592
|
+
return wrapped;
|
|
1593
|
+
},
|
|
1594
|
+
wrapSerialCommand(fn) {
|
|
1595
|
+
const wrapped = async (uid, ...args) => {
|
|
1596
|
+
await enqueueCommand(uid, async () => {
|
|
1597
|
+
if (!states[uid]) {
|
|
1598
|
+
return;
|
|
1599
|
+
}
|
|
1600
|
+
const generation = getGeneration(uid);
|
|
1601
|
+
const {
|
|
1602
|
+
newState,
|
|
1603
|
+
oldState
|
|
1604
|
+
} = states[uid];
|
|
1605
|
+
const newerState = await fn(newState, ...args);
|
|
1606
|
+
if (oldState === newerState || newState === newerState) {
|
|
1607
|
+
return;
|
|
1608
|
+
}
|
|
1609
|
+
if (!isCurrentGeneration(uid, generation)) {
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
const latestOld = states[uid];
|
|
1613
|
+
const latestNew = {
|
|
1614
|
+
...latestOld.newState,
|
|
1615
|
+
...newerState
|
|
1616
|
+
};
|
|
1617
|
+
states[uid] = {
|
|
1618
|
+
newState: latestNew,
|
|
1619
|
+
oldState: latestOld.oldState,
|
|
1620
|
+
scheduledState: latestNew
|
|
1621
|
+
};
|
|
1622
|
+
});
|
|
1623
|
+
};
|
|
1624
|
+
return wrapped;
|
|
1554
1625
|
}
|
|
1555
1626
|
};
|
|
1556
1627
|
};
|