I think it's a good idea. FYI, there is a plugin that already allows this, you just have to add it as a dependency, but it's not backward compatible https://github.com/edewit/aerogear-reflect-cordova
2018-04-29 16:44 GMT+02:00 Wojciech Trocki <wtro...@redhat.com>: > Hi Maksim > > `if (METHOD_1.equals(action))` is very similar way to how redux works. > > I have playing with your proposition to see how this could be implemented. > What I found is that processing annotations on runtime can contribute to > slower application startup due to fact that annotation needs to be > processed at runtime. > Deviceready event is delivered later, which is not desired. This could be > also processed on build time (something like dagger), but I did not > investigated that. > > I figured out simple way to extend this without any sacrifice on > performance. > This will simplify end user api and also still provide full backwards > compatibility. > We could make improvement for developers without affecting end user app > performance. > > Linking gist with the idea: > https://gist.github.com/wtrocki/43bfdda18c086a3283bb8ba3bf2d052e > > Happy to contribute that back to the Cordova. > > *Note: *I'm not maintainer of Cordova Android platform so my response do > not mean that there will be approval for this change. > > > On Sun, Apr 29, 2018 at 9:58 AM, chemeri...@gmail.com < > chemeri...@gmail.com> > wrote: > > > Hi guys. cordova-ios has a nice method binding for plugins. Unfortunately > > cordova-android requires at present boilerplate implementation of method > > execute: > > > > public class MyPlugin extends CordovaPlugin { > > ... > > @Override > > public boolean execute(String action, JSONArray args, CallbackContext > > callbackContext) throws JSONException { > > if (METHOD_1.equals(action)) { > > method1(args, callbackContext); > > } else if (METHOD_2.equals(action)) { > > method2(args, callbackContext); > > ... > > } else { > > return false; > > } > > return true; > > } > > ... > > } > > > > I suggest to implement support for @CordovaMethod that will allow for > > plugin authors to reduce boilerplate code, so the implementation above > will > > look like: > > > > public class MyPlugin extends CordovaPlugin { > > ... > > @CordovaMethod > > private void method1(JSONArray args, CallbackContext callbackContext) > > throws JSONException { > > ... > > } > > > > @CordovaMethod > > private void method2(JSONArray args, CallbackContext callbackContext) > > throws JSONException { > > ... > > } > > ... > > } > > > > Implementation of method execute in CordovaPlugin.java will check for > > methods marked with @CordovaMethod and if action argument matches a > method > > with @CordovaMethod, the method will be invoked. Developer can also > specify > > action manually via the name parameter: > > > > public class MyPlugin extends CordovaPlugin { > > ... > > @CordovaMethod(name = "method1") > > private void myMethod(JSONArray args, CallbackContext > callbackContext) > > throws JSONException { > > ... > > } > > ... > > } > > > > Important to note that backward compatibility is preserved - old plugins > > didn't have @CordovaMethod, but new ones can use it to simplify code. > > > > What do you think? > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: dev-unsubscr...@cordova.apache.org > > For additional commands, e-mail: dev-h...@cordova.apache.org > > > > > > > -- > > WOJCIECH TROCKI > > Red Hat Mobile <https://www.redhat.com/> > > IM: wtrocki > <https://red.ht/sig> >