slint/docs/tutorial/node/src/main_tiles_from_js.js
Simon Hausmann 7576ea71f2 Node.js tutoria: Use await when calling run()
As it happens, the run() call is the last call in the app, so it also works without
await. But the moment somebody
adds code after run(), they'd be surprised
that it gets called
"before" run. So await for good measure.
2023-11-07 09:04:32 +01:00

23 lines
620 B
JavaScript

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: MIT
// ANCHOR: main
// main.js
import * as slint from "slint-ui";
let ui = slint.loadFile("./memory.slint");
let mainWindow = new ui.MainWindow();
let initial_tiles = mainWindow.memory_tiles;
let tiles = initial_tiles.concat(initial_tiles.map((tile) => Object.assign({}, tile)));
for (let i = tiles.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * i);
[tiles[i], tiles[j]] = [tiles[j], tiles[i]];
}
let model = new slint.ArrayModel(tiles);
mainWindow.memory_tiles = model;
await mainWindow.run();
// ANCHOR_END: main