Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter::Function does not work on WASM backend #66

Open
v3xro opened this issue Jul 26, 2024 · 8 comments · May be fixed by #67
Open

Formatter::Function does not work on WASM backend #66

v3xro opened this issue Jul 26, 2024 · 8 comments · May be fixed by #67

Comments

@v3xro
Copy link

v3xro commented Jul 26, 2024

You can create e.g. an AxisLabel with Formatter::Function in WASM, but it will be rendered as a string with the RAW_MARK prefix/suffix #*#*#*# and will not be available to call from JS. Unsure how to get it to work presently.

@v3xro v3xro linked a pull request Jul 26, 2024 that will close this issue
@sangelxyz
Copy link

Do you have an example of how to use this in wasm ?

@v3xro
Copy link
Author

v3xro commented Aug 3, 2024

Yes, currently it would look like:

Formatter::Function(js_sys::Function::new_with_args(
                        "arg1, arg2, arg3",
                        r#"return arg1 + arg2 + arg3;"#,
                    ))

However I noticed that my PR does not make the code compatible with non-wasm targets. I think you could probably provide a From<(String, String)> on both WASM and SSR targets, the former calling js_sys::Function::new_with_args and the latter printing out the function definition fully e.g. format!("function ({args}) { {body} }", ..). I might update the PR with that as it seems a simple enough workaround for the types needing (necessarily) to be different.

@sangelxyz
Copy link

Nice, thank you. I'll keep an eye on the update. I'm only using wasm with a leptos project.

@tqwewe
Copy link

tqwewe commented Nov 2, 2024

Hi, is there any updates on this? Currently I don't think I can provide my own function for this

@LukaOber
Copy link
Collaborator

LukaOber commented Nov 3, 2024

Hi, is there any updates on this? Currently I don't think I can provide my own function for this

You can try out the PR referenced above. But this is not yet fixed/implemented on main.

@sangelxyz
Copy link

Hi, is there any updates on this? Currently I don't think I can provide my own function for this

I'm using the PR in a leptos project, it's working great.

@LukaOber
Copy link
Collaborator

LukaOber commented Nov 3, 2024

Can you provide a small example? And do you know if the formatter functions work with ssr? If you don't know, I will check it myself.

@sangelxyz
Copy link

sangelxyz commented Nov 4, 2024

Can you provide a small example? And do you know if the formatter functions work with ssr? If you don't know, I will check it myself.

sure, i'll make a simple SSR example and post tomorrow.

formatter functions work with ssr

it will fail without a feature flag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants