-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1012 from alexcrichton/rename-exported-type
Implement support for `js_class` on exported types
- Loading branch information
Showing
8 changed files
with
142 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
guide/src/reference/attributes/on-rust-exports/js_class.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# `js_class = Blah` | ||
|
||
The `js_class` attribute is used to indicate that all the methods inside an | ||
`impl` block should be attached to the specified JS class instead of inferring | ||
it from the self type in the `impl` block. The `js_class` attribute is most | ||
frequently paired with [the `js_name` attribute](js_name.html) on structs: | ||
|
||
```rust | ||
#[wasm_bindgen(js_name = Foo)] | ||
pub struct JsFoo { /* ... */ } | ||
|
||
#[wasm_bindgen(js_class = Foo)] | ||
impl JsFoo { | ||
#[wasm_bindgen(constructor)] | ||
pub fn new() -> JsFoo { /* ... */ } | ||
|
||
pub fn foo(&self) { /* ... */ } | ||
} | ||
``` | ||
|
||
which is accessed like: | ||
|
||
```rust | ||
import { Foo } from './my_module'; | ||
|
||
const x = new Foo(); | ||
x.foo(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters