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

feat: allow using Formatter::Function from WASM #67

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

v3xro
Copy link

@v3xro v3xro commented Jul 26, 2024

We can create functions directly using js_sys::Function::new_with_args for example when using WASM. Fixes #66

@v3xro v3xro force-pushed the feat/tooltip-value-formatter branch from 2926354 to 9c8d993 Compare September 6, 2024 14:22
@v3xro
Copy link
Author

v3xro commented Sep 6, 2024

I've updated the PR so that it's possible to express a function that would work both in a SSR and WASM context (via FormatterFunction::new_no_args/new_with_args) that wraps the js_sys::Function type. Hopefully this is not too repetitive.

@tqwewe
Copy link

tqwewe commented Nov 6, 2024

This doesn't seem to compile on wasm because the js_sys::Function type doesn't implement Serialize. I realized you forgot to add #[serde(with = "serde_wasm_bindgen::preserve")] to the js_sys function in the latest force commit

Also, its probably worth adding this from impl:

#[cfg(target_arch = "wasm32")]
impl From<web_sys::js_sys::Function> for FormatterFunction {
    fn from(f: web_sys::js_sys::Function) -> Self {
        FormatterFunction { value: f }
    }
}

@LukaOber
Copy link
Collaborator

LukaOber commented Nov 7, 2024

@sangelxyz you are using this PR in a leptos project, right? So you are able to use this in a wasm context?

@sangelxyz
Copy link

sangelxyz commented Nov 7, 2024

@sangelxyz you are using this PR in a leptos project, right? So you are able to use this in a wasm context?

Yes commit 67 does work.

I uploaded a leptos SSR example here.
https://github.com/sangelxyz/leptos-charing-formatter-function

you can see it in use
https://higherhighs.com/stocks/438909/CACI/

You do need a feature tag in order for it to compile in an ssr/wasm context..

@tqwewe
Copy link

tqwewe commented Nov 7, 2024

@sangelxyz i took a look at your repo, and the charming dependency is specified as a path. I'm thinking your local repo is not up to date with this PR. Are you able to share the FormatterFunction struct definition in your local charming clone here just to clarify it's the same with the latest in this PR

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 this pull request may close these issues.

Formatter::Function does not work on WASM backend
4 participants