Skip to content

Commit f41b53d

Browse files
committed
Add interop doc example for .addFacade
1 parent 50248d7 commit f41b53d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: doc/INTEROP.md

+40
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,46 @@ object ReactCollapse {
8080
}
8181
```
8282

83+
Example for `.addFacade[F]`.
84+
```javascript
85+
// The JavaScript
86+
class AddFacadeExample extends React.Component {
87+
constructor(props) {
88+
super(props);
89+
this.state = { num1: 123, num2: 500 };
90+
}
91+
92+
// method that needs to be accessible on the component
93+
inc() {
94+
this.setState({ num1: this.state.num1 + 1 });
95+
}
96+
97+
render() {
98+
return React.createElement("div", null, "State = ", this.state.num1, " + ", this.state.num2, this.props.children);
99+
}
100+
}
101+
```
102+
```scala
103+
// The Scala facade
104+
object AddFacadeExample {
105+
@JSGlobal("AddFacadeExample")
106+
@js.native
107+
object RawComponent extends js.Object
108+
109+
@js.native
110+
trait JsState extends js.Object {
111+
val num1: Int
112+
val num2: Int
113+
}
114+
115+
@js.native
116+
trait JsMethods extends js.Object {
117+
def inc(): Unit = js.native
118+
}
119+
120+
val component = JsComponent[Null, Children.None, JsState](RawComponent).addFacade[JsMethods]
121+
}
122+
```
83123

84124
## Using JS functional components in Scala
85125

0 commit comments

Comments
 (0)