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

Prototype inheritance #1737

Closed
wants to merge 1 commit into from
Closed

Conversation

eggyal
Copy link

@eggyal eggyal commented Aug 27, 2019

Prototype implementation for draft RFC. Fixes #210 and fixes #1721.

Enables one to do stuff like this—

#[wasm_bindgen(prototype=web_sys::HtmlElement)]
struct MyCustomElement {}

#[wasm_bindgen]
impl MyCustomElement {
    #[wasm_bindgen(constructor)]
    fn new() -> WasmType<MyCustomElement> {
        instantiate! { MyCustomElement{} }
    }
}

// ...

web_sys::window()
    .unwrap()
    .custom_elements()
    .define("my-custom-element", &js_sys::JsFunction::of::<MyCustomElement>())?;

// ...

See Exporting a struct to JS for detailed information, and the examples prefixed web-components- for use-cases.

crates/backend/src/codegen.rs Outdated Show resolved Hide resolved
@eggyal eggyal force-pushed the prototype-inheritance branch from dc0dacd to 8b9ac19 Compare August 27, 2019 12:52
@eggyal eggyal force-pushed the prototype-inheritance branch 2 times, most recently from f7d1428 to df96753 Compare September 1, 2019 11:39
@eggyal eggyal force-pushed the prototype-inheritance branch 3 times, most recently from 0fe93d7 to 91db9e8 Compare September 11, 2019 19:03
@eggyal eggyal closed this Sep 30, 2019
@eggyal eggyal force-pushed the prototype-inheritance branch from 91db9e8 to 6d1dc81 Compare September 30, 2019 17:20
@eggyal eggyal reopened this Sep 30, 2019
@eggyal eggyal force-pushed the prototype-inheritance branch 2 times, most recently from c029f58 to 8c3d7df Compare October 3, 2019 01:14
@eggyal eggyal force-pushed the prototype-inheritance branch from 8c3d7df to 3fdac76 Compare October 3, 2019 01:35
@alexcrichton
Copy link
Contributor

I'm going to close this while the RFC makes progress to help clean out PRs.

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.

Enable exported Rust structs to specify prototypal inheritance Add ability to import and extend JS classes
2 participants