The wrapper returned should behave like Model<T>, which now also a
@@iterator key. That key is generated by simulation the evaluation of
`Symbol.iterator`, by first looking up `Symbol` in the global object,
and then `iterator`. When retrieving `Symbol` we casted it to a
`JsObject`, but commit
aeb0b4766d
upstream tightened the cast by adding an extract check, which fails.
Symbol is not a plain object, it's in fact a function (by use of
`Symbol()`).
Add a convenience pop() function (we already have push...) and re-use the model
instead of fetching it.
Previously we fetched it because it was converted to
a new array every time.
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.
- We could import from `npm:...` directly, but by using an import map, the import is centrally controlled and all subsequent snippets for Node.js can also be used with Deno
- Use .mjs for the node snippet as we use ES module syntax
Unfortunately our own examples can't be equipped with a deno.json yet as
deno does not support yet imports of node modules from a local path.
They are not commonly used so no need to use semi-public api for that
and it's really easy to similate with ust two clicks anyway
The previous test function were added before there was public way to
send events
These are built with the default features of the interpreter crate, as
unfortunately napi-rs doesn't allow us to select features on the command
line yet. The next version (3.0) will add that, then we can keep the
binaries in sync.
So meanwhile, these are basically winit/femtovg/software enabled
binaries.
cc #1991
Commit 84fd6dc08c changed the import
from "rust-module" to "rust-module.cjs", which unfortunately broke
typedoc's visibility into the types. Revert back to using the import
without extension. With the given tsconfig files that works now and
typedoc publishes the docs for the re-exported types again.
Fixes#4153
- 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.
* Added more documentation to the node port
* Update api/node/index.ts
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
* Update api/node/index.ts
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
* Update api/node/index.ts
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>
* code review feedback
---------
Co-authored-by: Simon Hausmann <simon.hausmann@slint.dev>