Commit graph

7 commits

Author SHA1 Message Date
Simon Hausmann
a211a104a1 Node.js: Implement Iterable<T> for Model<T>
This makes it much easier to extra data from Models, such as using them
in for loops. This is the equivalent of Model::iter() in Rust.
2024-02-26 15:02:41 +01:00
Simon Hausmann
841cb25565 Node.js: Always map Slint arrays to Model<T> in JavaScript
This gives a consistent interface - there's no more need to check the result of a property read on whether it's an array or a model.
2024-02-26 15:02:41 +01:00
Simon Hausmann
fa8e847f7c Fix bi-directional mapping of Model<T> from Node.js to Rust
A Model<T> stores a reference to a External<Rc<ModelNotify>>.
Every time such a Model<T> needs to be exposed to Slint/Rust, we create
a TypedRustModel that wraps the Rc<ModelNotify>, a strong reference to
the JS object, and the Type field for the expected data type (the
interpreter expects). The Model trait is implemented on TypedRustModel,
which means it is allocated every time the conversion is needed, but the
underlying Rc<ModelNotify> is shared and thus the (forwarded) ModelNotify.

When converting back to JavaScript, we downcast_ref to the
TypedRustModel and fetch the original JavaScript object - if available.
2024-02-26 15:02:41 +01:00
Simon Hausmann
2d6edfbd6c Node.js: Fix MapModel rowData() calling map function even if the source model returned undefined
Also fix the function signature, which was wrong.
2024-02-07 19:15:02 +01:00
Florian Blasius
5af7095fc9
move mapmodel to private_api (#4015)
Moved MapModel to private api because it is not ready now until the notify mechanism for node models is improved.
2023-11-27 13:11:31 +01:00
Florian Blasius
b19cbba7ad
node: added MapModel (#3946)
---------

Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
2023-11-23 12:20:06 +01:00
Simon Hausmann
84fd6dc08c Clean up Node.js port build system
- Instead of building index.js with esbuild and generating types with
  tsc, use tsc to build index.js and index.d.ts.
- Use ts-node instead of swc for typescript based tests, as that
  works with es modules.
- Remove "syntax_check" target from package.json as that's now
  implied with "compile".
- Sadly this requires one "as any" cast as tsc somehow fails to
  determine the right type info for node-fetch.

Unfortunately index.js can't be an ES module without breaking
compatiblity. It would imply that the Node.js port can't be used with
require() anymore. So even thought that would simplify things further,
it's not part of this PR.
2023-11-21 07:20:21 +01:00
Renamed from api/node/__test__/js_value_conversion.spec.ts (Browse further)