Giter Site home page Giter Site logo

Comments (6)

yukinarit avatar yukinarit commented on June 6, 2024 1

Hi @shimatar0!
Oh, It seems my prior implementation for MarkerOptions is pretty much incomplete! This issue shouldn't have "good first issue" label πŸ˜‚

Can you please try if this implementation works?

impl MarkerOptions {
   pub fn build(mut self) -> JsValue {
       let obj: js_sys::Object = serde_wasm_bindgen::to_value(&self).unwrap().into();
       if let Some(element) = self.element.take() {
           js_sys::Object::define_property(&obj, &JsValue::from_str("element"), &*element).into()
       } else {
           obj.into()
       }
    }
}

from mapbox-gl-rs.

yukinarit avatar yukinarit commented on June 6, 2024 1

Yes, element needs to have #[serde(skip)], because it's not serializable. My implementation serializes MarkerOptions without element into JsValue first. Then it appends element property of HtmlElement into the JsValue. Hope this will work.

from mapbox-gl-rs.

shimatar0 avatar shimatar0 commented on June 6, 2024 1

@yukinarit
Sorry. It took me a while to checkπŸ˜‚
I understand, but there still seemed to be a problem, so I put out a PR for WIP and commented!

from mapbox-gl-rs.

shimatar0 avatar shimatar0 commented on June 6, 2024

@yukinarit
Hi! In addressing this issue, found some concerns.
Perhaps this requires creating an HttpElement to customize the MakerOption structure,
but the HttpElement is likely to skip serialization.
https://github.com/yukinarit/mapbox-gl-rs/blob/main/src/marker.rs#L15-L16

I think that HttpElement may be a bit difficult to deal with as it does not seem to have a serialize/deserialize traitπŸ€”
I can't really think of a better ideaπŸ˜‚

from mapbox-gl-rs.

shimatar0 avatar shimatar0 commented on June 6, 2024

@yukinarit
Thanks!
I feel that this would allow the structure members themselves to be serialized when passing through the build method.

However, I think the following structure definitions may be the bottleneck.(HtmlElement)
e.g.
MarkerOptions
https://github.com/yukinarit/mapbox-gl-rs/blob/main/src/marker.rs#L15-L16

    ...
    // todo keep serialization from skipping.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub element: Option<web_sys::HtmlElement>,
    ...

Is this error likely?

the trait bound `HtmlElement: Serialize` is not satisfied
the following other types implement trait `Serialize`:

from mapbox-gl-rs.

yukinarit avatar yukinarit commented on June 6, 2024

Done in #42

from mapbox-gl-rs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.