mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-01 16:17:25 +00:00

* Update api/node/typescript/models.ts Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev> * Code review feedback --------- Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
|
|
|
import test from "ava";
|
|
import * as path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
import {
|
|
loadFile,
|
|
loadSource,
|
|
CompileError,
|
|
ArrayModel,
|
|
private_api,
|
|
Model,
|
|
} from "../dist/index.js";
|
|
|
|
test("MapModel notify rowChanged", (t) => {
|
|
const source = `
|
|
export component App {
|
|
|
|
in-out property <[string]> model;
|
|
in-out property <string> changed-items;
|
|
|
|
for item in root.model : Text {
|
|
text: item;
|
|
|
|
changed text => {
|
|
root.changed-items += self.text;
|
|
}
|
|
}
|
|
}`;
|
|
|
|
const path = "api.spec.ts";
|
|
|
|
private_api.initTesting();
|
|
const demo = loadSource(source, path) as any;
|
|
const instance = new demo.App();
|
|
|
|
interface Name {
|
|
first: string;
|
|
last: string;
|
|
}
|
|
|
|
const nameModel: ArrayModel<Name> = new ArrayModel([
|
|
{ first: "Hans", last: "Emil" },
|
|
{ first: "Max", last: "Mustermann" },
|
|
{ first: "Roman", last: "Tisch" },
|
|
]);
|
|
|
|
const mapModel = new private_api.MapModel(nameModel, (data) => {
|
|
return data.last + ", " + data.first;
|
|
});
|
|
|
|
instance.model = mapModel;
|
|
|
|
private_api.send_mouse_click(instance, 5, 5);
|
|
|
|
nameModel.setRowData(0, { first: "Simon", last: "Hausmann" });
|
|
nameModel.setRowData(1, { first: "Olivier", last: "Goffart" });
|
|
|
|
private_api.send_mouse_click(instance, 5, 5);
|
|
|
|
t.is(instance.changed_items, "Goffart, OlivierHausmann, Simon");
|
|
});
|