nbrugger-tgm / reactj

A reactive ui lib for easy MVC
LaTeX Project Public License v1.3c
10 stars 0 forks source link

[Refactor] Replace Proxy.reactTo() with method level @React #34

Closed nbrugger-tgm closed 3 years ago

nbrugger-tgm commented 3 years ago

The way to specify custom methods to react to is a little cumbersome and error prone.

Before

ReactiveProxy<Person> person = ReactiveProxy.createProxy(Person.class);
person.setStrategy(REACT_ON_CUSTOM);
person.reactTo(
    "updateHealthStatus",
    "setAge"
);

After

@ReactTo(ANNOTATION);
public class Person {
    @Reactive
    public updateHealthStatus(ECard card){
          ....
    }
    @Reactive
    public setAge(int age){
        ...
    }
}

Alernative

public class Person {
    @Reactive
    public updateHealthStatus(ECard card){
          ....
    }
    @Reactive
    public setAge(int age){
        ...
    }
}
ReactiveProxy<Person> person = ReactiveProxy.createProxy(Person.class);
person.setStrategy(ANNOTATIONS);
nbrugger-tgm commented 3 years ago

Requirement

@ReactTo should take theese options

nbrugger-tgm commented 3 years ago

Adaptation

Due to #39 #44 #38 and #45 the creation process of proxies changed and therefore a new approach is needed!

Design

We will go with the following approach

Owned classes

public class Person {
@Reactive
public updateHealthStatus(ECard card){
....
}
@Reactive
public setAge(int age){
...
}
}
ProxyCreator creator = ProxyCreator.besideOrigin();
creator.setStrategy(ANNOTATIONS);
ReactiveProxy<Person> person = creator.createProxy(new Person());

Or for 3rd party classes

ProxyCreator creator = ProxyCreator.custom(getClass());//custom is the best for 3rd party
creator.setStrategy(SETTERS);
//or
creator.setStrategy(byName("update","erase"));
ReactiveProxy<Matrix> person = creator.create(new Matrix());
nbrugger-tgm commented 3 years ago

Released in v4.0.0b8