davinkevin / AngularStompDK

Angular service to communicate to Stomp-Websocket
http://davinkevin.github.io/AngularStompDK/
Apache License 2.0
36 stars 12 forks source link

Providing a more fluent api to ngStomp Service #9

Closed davinkevin closed 8 years ago

davinkevin commented 9 years ago

We have now some parameters for each functions, so it's simple to mix up the order of parameters. For example :

ngstomp
        .subscribe('/topic/item', whatToDoWhenMessageComming, {}, $scope)

We have 4 parameters :

Some parameters are optional, like the scope and the headers, so if you want to unsubscribe from scope, you have to send useless object describing the headers...

I want to add a more intuitive and fluent API like this (proposition) :

ngstomp
        .subscribeTo('/topic/item')
                .callback(whatToDoWhenMessageComming)
                .withHeaders({})
                .bindTo($scope)
        .build() /* ... or something else */

And if we have multiple subscribe :

ngstomp
        .subscribeTo('/topic/item')
                .callback(whatToDoWhenMessageComming)
                .bindTo($scope)
        .and()
        .subscribeTo('/topic/item')
                .callback(whatToDoWhenMessageComming)
                .withHeaders({})
        .build();

Let me know if you have a better idea and help with PR ;)