Skip to content

Commit db3de15

Browse files
committed
Update documentation with @JSmethod
1 parent ebfc92b commit db3de15

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+128
-93
lines changed

docs-source/book/advanced/extending-components.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Let's say we have the following Component:
2323
public abstract class ParentComponent extends VueComponent {
2424
@JsProperty String parentMessage = "This is a message from the parent";
2525

26+
@JsMethod
2627
public int parentMultiplyBy2(int value) {
2728
return value * 2;
2829
}

docs-source/book/essential/class-and-style.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,11 @@ It is often a good idea to bind to a style object directly so that the template
199199
```
200200
```java
201201
@Component
202-
public class StylishComponent extends VueComponent {
202+
public class StylishComponent extends VueComponent implements HasCreated {
203203
@JsProperty JsObject<String> styleObject;
204204

205-
public StylishComponent() {
205+
@Override
206+
public void created() {
206207
this.styleObject = map(e("color", "red"), e("fontSize", "20px"));
207208
}
208209
}

docs-source/book/essential/components.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,15 @@ The proper answer to these use cases are:
294294

295295
```java
296296
@Component
297-
public class MyComponent extends VueComponent {
297+
public class MyComponent extends VueComponent implements HasCreated {
298298
@Prop
299299
@JsProperty
300300
public String initialCounter;
301301

302302
@JsProperty String counter;
303303

304-
public MyComponent() {
304+
@Override
305+
public void created() {
305306
this.counter = this.initialCounter;
306307
}
307308
}
@@ -438,6 +439,7 @@ Here's an example:
438439
public class ButtonCounterComponent extends VueComponent {
439440
@JsProperty int counter = 0;
440441

442+
@JsMethod
441443
public void increment() {
442444
this.counter++;
443445
// When incrementing, we fire an event.
@@ -459,6 +461,7 @@ public class ButtonCounterComponent extends VueComponent {
459461
public class CounterWithEventComponent extends VueComponent {
460462
@JsProperty int total = 0;
461463

464+
@JsMethod
462465
public void incrementTotal() {
463466
this.total++;
464467
}
@@ -486,6 +489,7 @@ For example, let's change our counter component to pass the value of it's counte
486489
public class ButtonCounterComponent extends VueComponent {
487490
@JsProperty int counter = 0;
488491

492+
@JsMethod
489493
public void increment() {
490494
this.counter++;
491495
// Pass the current value of the counter with the event.
@@ -511,6 +515,7 @@ public class CounterWithEventComponent extends VueComponent {
511515
@JsProperty int total = 0;
512516

513517
// But we can now get the value of the event as parameter
518+
@JsMethod
514519
public void incrementTotal(int childCounterValue) {
515520
this.total += childCounterValue;
516521
}

docs-source/book/essential/computed-and-watchers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public class ReverseComponent extends VueComponent {
8181
@JsProperty String message = "Hello";
8282

8383
// Note that there a no more @Computed annotation
84+
@JsMethod
8485
public String getReversedMessage() {
8586
return new StringBuilder(message).reverse().toString();
8687
}

docs-source/book/essential/events.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ For example:
4545
```java
4646
@Component
4747
public class GreetComponent extends VueComponent {
48+
@JsMethod
4849
public void greet() {
4950
Window.alert("Hello from GWT!");
5051
}
@@ -79,6 +80,7 @@ Instead of binding directly to a method name, we can also use methods in an inli
7980
```java
8081
@Component
8182
public class HiWhatComponent extends VueComponent {
83+
@JsMethod
8284
public void say(String message) {
8385
Window.alert(message);
8486
}

docs-source/book/essential/forms.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ In those case you can use the following syntax:
7474
public class TodoTextComponent extends VueComponent {
7575
@JsProperty Todo todo = new Todo("Hello World!");
7676

77+
@JsMethod
7778
public void updateMessage(NativeEvent event) {
7879
this.todo.setText(JsTools.get(event.getEventTarget(), "value"));
7980
}

docs-source/book/introduction/README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ public class SimpleLinkComponent extends VueComponent {
3434

3535
##### Why `@JsProperty`?
3636

37-
Only `JsInterop` attributes of our Class will be accessible in our template.
37+
Only `JsInterop` attributes and methods of our Class will be accessible in our template.
3838

3939
Meaning either:
4040

41-
* Adding the `@JsType` annotation to our Class and setting attributes to `public`
42-
* Adding the `@JsProperty` annotation to each attribute and setting them to at least `protected`.
41+
* Adding the `@JsType` annotation to our Class and setting attributes/methods to `public`
42+
* Adding the `@JsProperty`/`@JsMethod` annotation to each attribute/method and setting them to at least `package-protected`.
4343

44-
In this documentation we chose to use the `@JsProperty` annotation on properties.
44+
In this documentation we chose to use the `@JsProperty`/`@JsMethod` annotation on properties/methods.
4545

4646
##### HTML Template
4747

@@ -117,10 +117,7 @@ Behind the scene, our Java `VueComponent` Class is converted to the options that
117117
linkName: null
118118
},
119119
methods: {
120-
created: function() {
121-
const javaInstance = new SimpleLinkComponent();
122-
this.linkName = javaInstance.linkName;
123-
}
120+
...
124121
}
125122
}
126123
```
@@ -289,6 +286,7 @@ To let users interact with your app, we can use the `v-on` directive to attach e
289286
public class ExclamationComponent extends VueComponent {
290287
@JsProperty String message = "Hello Vue GWT!";
291288

289+
@JsMethod // Notice the @JsMethod annotation to expose this method to our template
292290
public void addExclamationMark() {
293291
this.message += "!";
294292
}
@@ -424,6 +422,7 @@ The `@Prop` annotation tells Vue GWT that our `todo` property will be passed fro
424422
Be careful, you still need to use the `@JsProperty` to tell VueGWT to not rename this property.
425423

426424
***TodoComponent.html***
425+
427426
```html
428427
<li>
429428
{{ todo.getText() }}

docs-source/examples/src/main/java/com/axellience/vuegwtexamples/client/examples/extendjavacomponent/ChildComponent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.axellience.vuegwt.client.component.hooks.HasCreated;
44
import com.axellience.vuegwt.jsr69.component.annotations.Component;
55
import com.axellience.vuegwt.jsr69.component.annotations.Computed;
6+
import jsinterop.annotations.JsMethod;
67
import jsinterop.annotations.JsProperty;
78

89
/**
@@ -19,11 +20,13 @@ public void created()
1920
this.childValue = 10;
2021
}
2122

23+
@JsMethod
2224
public int childMultiplyBy10(int value)
2325
{
2426
return value * 10;
2527
}
2628

29+
@JsMethod
2730
public int childMultiplyBy4(int value)
2831
{
2932
return this.parentMultiplyBy2(this.parentMultiplyBy2(value));

docs-source/examples/src/main/java/com/axellience/vuegwtexamples/client/examples/extendjavacomponent/ParentComponent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.axellience.vuegwt.client.component.VueComponent;
44
import com.axellience.vuegwt.jsr69.component.annotations.Component;
55
import com.axellience.vuegwt.jsr69.component.annotations.Computed;
6+
import jsinterop.annotations.JsMethod;
67
import jsinterop.annotations.JsProperty;
78

89
/**
@@ -13,6 +14,7 @@ public abstract class ParentComponent extends VueComponent
1314
{
1415
@JsProperty String parentMessage = "This is a message from the parent";
1516

17+
@JsMethod
1618
public int parentMultiplyBy2(int value)
1719
{
1820
return value * 2;

docs-source/examples/src/main/java/com/axellience/vuegwtexamples/client/examples/extendsjscomponent/ChildJavaComponent.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.axellience.vuegwt.jsr69.component.annotations.Component;
44
import com.axellience.vuegwt.jsr69.component.annotations.Computed;
55
import com.axellience.vuegwtexamples.client.examples.extendsjscomponent.parent.ParentJsComponent;
6+
import jsinterop.annotations.JsMethod;
67
import jsinterop.annotations.JsProperty;
78

89
/**
@@ -13,11 +14,13 @@ public class ChildJavaComponent extends ParentJsComponent
1314
{
1415
@JsProperty int childValue = 10;
1516

17+
@JsMethod
1618
public int childMultiplyBy10(int value)
1719
{
1820
return value * 10;
1921
}
2022

23+
@JsMethod
2124
public int childMultiplyBy4(int value)
2225
{
2326
return this.parentMultiplyBy2(this.parentMultiplyBy2(value));

0 commit comments

Comments
 (0)