Comments (7)
Ahh, words are hard.
console.log
is one type of "global" that's on window
or webworker's self
. In other words, you can call console.log
anywhere. It is global by default.
The solid-js store you're talking about is global once you export or import it. That's actually a significant difference, since that export means it isn't global until you make it global. It is not global by default.
Also, now that I think about it, I don't think option 3 would work because the override wouldn't be scoped to the web-worker. Any console.log
overrides would only apply to the console.log
in user-land, not in web-worker-land.
I made a small demo of option 2 here. Note how JS now owns that global mutable state for storing the user's callback function
from fsrs-browser.
Sorry, I'm not very familiar with Rust. need @AlexErrant to take a look and see if it can be implemented.🥲🥲🥲
from fsrs-browser.
progress bar itself is simple
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress
<label for="train">Train progress:</label>
<progress id="train" max="100" value="70">70%</progress>
so the main point is get value
for progress. Maybe need to write another wasm_bindgen
function to get the value, then bind the value
.
from fsrs-browser.
Unfortunately, I'm not seeing any obviously good ways of implementing this. I tried/thought of a few ways:
- Passing a Javascript function to Rust as a callback to put into a
MetricsRenderer
impl. Sadly, this means passing a closure, not a function pointer. This results in the following error message, which I'm unable to resolve:
Diagnostics:
1. `(dyn Fn(i32) + 'static)` cannot be shared between threads safely
the trait `std::marker::Sync` is not implemented for `(dyn Fn(i32) + 'static)`
required for `std::ptr::Unique<(dyn Fn(i32) + 'static)>` to implement `std::marker::Sync` [E0277]
2. `(dyn Fn(i32) + 'static)` cannot be sent between threads safely
the trait `Send` is not implemented for `(dyn Fn(i32) + 'static)`
required for `std::ptr::Unique<(dyn Fn(i32) + 'static)>` to implement `Send` [E0277]
I cannot pass a js_sys::Function
directly either because it's not send/sync. Trying to call the function in a rayon spawned thread results in the same type of error. I then tried making the function global by putting it in a OnceLock
, but again that errors. I don't think anything involving js_sys::Function
is viable - though I really want it it to be. I also tried web_sys::MessagePort
but it's also not send/sync.
- Notably this call using
extern "C"
works. But it only works for Javascript thatfsrs-browser
defines. Ideally, it would work with user-defined Javascript, since everyone will want to update their UI differently. It only works forfsrs-browser
defined JS because of how wasm-bindgen handles JS snippets. JS snippets are copied to the package in a hashed manner, for examplefsrs-browser/pkg/snippets/fsrs-browser-0a7bb84009d44696/js/foo.js
. This hash means there's no stable path for users to use to set any callback functions.
A workaround would be passing the function to Rust, which would then set that callback function in some JS snippet for extern C
to use. This... feels like quite a bad hack, since JS now owns that global mutable state for storing the user's callback function.
- Since calls to
console.log
work, users could override theconsole.log
implementation in JS. Obviously this is a terrible solution.
I'd love to somehow make 1. work, but I'm running into the limits of my Rust skills. Are there any other things I could try? std::sync::mpsc
also has the same limitations.
from fsrs-browser.
A naive thought, what if change console.log to setValue, since
calls to console.log work
somethings like
import { render } from "solid-js/web";
import { createSignal } from "solid-js";
function Counter() {
const [count, setCount] = createSignal(0);
setInterval(() => setCount(count() + 1), 1000); // setCount change to setProgress
return <div>Count: {count()}</div>;
}
render(() => <Counter />, document.getElementById('app'));
https://www.solidjs.com/tutorial/introduction_signals?solved
from fsrs-browser.
The reason console.log
works is because it's in the global scope. Unfortunately setCount
is not in global scope.
I ended up going with another solution that uses (abuses?) shared memory. See the above PR for details.
from fsrs-browser.
setCount is not in global scope.
I don't know if it works.
For example, we can build a global reactive data store by creating a signal in a global scope, and exporting it for other modules to use:
https://www.solidjs.com/tutorial/stores_nocontext
from fsrs-browser.
Related Issues (10)
- hanging `Installing wasm-bindgen...` HOT 2
- Fsrs.testSerialization is not a function HOT 2
- [BUG] The hard-coded timezone in anki_to_fsrs HOT 3
- [BUG] Maximum call stack size exceeded HOT 12
- [BUG?]Uncaught Error: null pointer passed to rust HOT 2
- Is this project still active? HOT 3
- simplify the arguments of fn compute_weights
- [Question] What's the next step of this repo? HOT 3
- [Bug] unable to train HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fsrs-browser.