story: Update Table story to generate increment id. (#1670)
Close #1661
This commit is contained in:
parent
f2cbc16655
commit
bdc5ce4b6e
1 changed files with 16 additions and 1 deletions
|
|
@ -42,6 +42,7 @@ struct Counter {
|
|||
|
||||
static ALL_COUNTERS: LazyLock<Vec<Counter>> =
|
||||
LazyLock::new(|| serde_json::from_str(include_str!("./fixtures/counters.json")).unwrap());
|
||||
static INCREMENT_ID: LazyLock<std::sync::Mutex<usize>> = LazyLock::new(|| std::sync::Mutex::new(0));
|
||||
|
||||
impl Counter {
|
||||
fn random() -> Self {
|
||||
|
|
@ -124,7 +125,15 @@ impl Stock {
|
|||
}
|
||||
|
||||
fn random_stocks(size: usize) -> Vec<Stock> {
|
||||
(0..size)
|
||||
// Incremental ID with size.
|
||||
let start = {
|
||||
let mut id_lock = INCREMENT_ID.lock().unwrap();
|
||||
let start = *id_lock;
|
||||
*id_lock += size + 1;
|
||||
start
|
||||
};
|
||||
|
||||
(start..start + size)
|
||||
.map(|id| Stock {
|
||||
id,
|
||||
counter: Counter::random(),
|
||||
|
|
@ -268,6 +277,12 @@ impl StockTableDelegate {
|
|||
}
|
||||
|
||||
fn update_stocks(&mut self, size: usize) {
|
||||
// Reset incremental ID
|
||||
{
|
||||
let mut id_lock = INCREMENT_ID.lock().unwrap();
|
||||
*id_lock = 0;
|
||||
}
|
||||
|
||||
self.stocks = random_stocks(size);
|
||||
self.eof = size <= 50;
|
||||
self.loading = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue