Skip to content

Commit

Permalink
Refactored to use the action type as parameter for the process methods
Browse files Browse the repository at this point in the history
  • Loading branch information
hpehl committed Mar 10, 2015
1 parent b618df1 commit e4cd1f6
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 519 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -80,7 +80,7 @@ public class TodoStore {
private final List<Todo> todos;

@Process(actionType = SaveTodo.class)
public void onSave(final Todo todo, final Dispatcher.Channel channel) {
public void onSave(final SaveTodo todo, final Dispatcher.Channel channel) {
// persist the todo (backend call)
}
}
Expand Down Expand Up @@ -139,7 +139,7 @@ Circuit allows you to express dependencies between Stores on the level of an Act
```java
public class TodoStore {
@Process(actionType = RemoveUser.class, dependencies = {UserStore.class})
public void onRemoveUser(String user, final Dispatcher.Channel channel) {
public void onRemoveUser(RemoveUser user, final Dispatcher.Channel channel) {
// when a user is removed we removes his todo's
[...]
}
Expand Down Expand Up @@ -172,10 +172,10 @@ When Stores complete the processing of an Action, they acknowledge the Action th
public class TodoStore {

@Process(actionType = SaveTodo.class)
public void onSave(final Todo todo, final Dispatcher.Channel channel) {
public void onSave(final SaveTodo todo, final Dispatcher.Channel channel) {

// async invocation
todoService.save(todo, new TodoCallback<Void>(channel) {
todoService.save(todo.getTodo(), new TodoCallback<Void>(channel) {
@Override
public void onSuccess(final Void result) {
// acknowledgement
Expand Down Expand Up @@ -248,8 +248,8 @@ public class ShoesStore {
The signature for methods annotated with `@Process` must adhere the following rules:

- The return type must be `void`
- Parameters 0..n-1 map to the action's payload. For each parameter there must be a getter in the action.
- The last parameter (or the only one, if no payload is referenced) must be of type `org.jboss.gwt.circuit.Dispatcher.Channel`.
- The last parameter (or the only one, if no action is referenced) must be of type `org.jboss.gwt.circuit.Dispatcher.Channel`.
- The first parameter can be the action which is processed.

To see the annotations in action take a look at the [wardrobe](samples/wardrobe) and [todo](samples/todo) samples.

Expand Down
37 changes: 0 additions & 37 deletions meta/src/main/java/org/jboss/gwt/circuit/meta/ActionType.java

This file was deleted.

14 changes: 8 additions & 6 deletions meta/src/main/java/org/jboss/gwt/circuit/meta/Process.java
Expand Up @@ -21,25 +21,27 @@
*/
package org.jboss.gwt.circuit.meta;

import org.jboss.gwt.circuit.Action;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Marks a method within a class annotated with {@link Store} as the method which should receive actions.
* The method must return void and have at least one parameter:
* <ul>
* The method must return void and must match one of these signatures:
* <ol>
* <li>Action w/o payload: A single parameter of type {@link org.jboss.gwt.circuit.Dispatcher.Channel} is required</li>
* <li>Action with payload: Parameters 0..n-1 are the action's payload, the last parameter must be
* the {@link org.jboss.gwt.circuit.Dispatcher.Channel}</li>
* </ul>
* <li>Action with payload: Two parameters. The first is the action, the second the
* {@link org.jboss.gwt.circuit.Dispatcher.Channel}</li>
* </ol>
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Process {

Class<?> actionType();
Class<? extends Action> actionType();

Class<?>[] dependencies() default {};
}
49 changes: 21 additions & 28 deletions pom.xml
Expand Up @@ -75,15 +75,15 @@
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<enterprise.cdi.version>1.2</enterprise.cdi.version>
<errai.version>3.0.0.Final</errai.version>
<freemarker.version>2.3.20</freemarker.version>
<gwt.version>2.6.1</gwt.version>

<!-- See https://issues.jboss.org/browse/ERRAI-760 -->
<guava.version>17.0</guava.version>
<auto-service.version>1.0-rc2</auto-service.version>
<auto-common.version>1.0-SNAPSHOT</auto-common.version>
<enterprise.cdi.version>1.2</enterprise.cdi.version>
<freemarker.version>2.3.22</freemarker.version>
<gwt.version>2.7.0</gwt.version>
<guava.version>18.0</guava.version>
<jgrapht.version>0.9.2-hal</jgrapht.version>
<junit.version>4.11</junit.version>
<junit.version>4.12</junit.version>
</properties>

<modules>
Expand Down Expand Up @@ -118,6 +118,16 @@
<artifactId>cdi-api</artifactId>
<version>${enterprise.cdi.version}</version>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
<version>${auto-service.version}</version>
</dependency>
<dependency>
<groupId>com.google.auto</groupId>
<artifactId>auto-common</artifactId>
<version>${auto-common.version}</version>
</dependency>

<!-- JGraphT -->
<dependency>
Expand All @@ -126,23 +136,12 @@
<version>${jgrapht.version}</version>
</dependency>

<!-- Errai -->
<dependency>
<groupId>org.jboss.errai.bom</groupId>
<artifactId>errai-version-master</artifactId>
<version>${errai.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- GWT & related -->
<dependency>
<groupId>org.jboss.errai</groupId>
<artifactId>errai-parent</artifactId>
<version>${errai.version}</version>
<type>pom</type>
<scope>import</scope>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
</dependency>

<!-- GWT & related -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava-gwt</artifactId>
Expand All @@ -153,11 +152,6 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
</dependency>

<!-- Freemarker -->
<dependency>
Expand Down Expand Up @@ -214,5 +208,4 @@
</snapshots>
</repository>
</repositories>

</project>
20 changes: 8 additions & 12 deletions processor/pom.xml
Expand Up @@ -46,21 +46,17 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service</artifactId>
</dependency>
<dependency>
<groupId>com.google.auto</groupId>
<artifactId>auto-common</artifactId>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgument>-proc:none</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
</project>

This file was deleted.

0 comments on commit e4cd1f6

Please sign in to comment.