wcandillon / swagger-js-codegen

A Swagger Codegen for typescript, nodejs & angularjs
Apache License 2.0
693 stars 286 forks source link

support passing arguments on $broadcast and $on events in angular client #57

Open borisirota opened 9 years ago

borisirota commented 9 years ago

A use case for that can be listening to getToken event and then automatically add the new generated token. something like:

var api = new API();

api.$on($scope, '/auth/token', function (token) {
    api.setToken(token);
});

api.getToken().then(function (data) {
    ...
    api.$broadcast('/auth/token', data.token);
    ...
}, function (err) { ... });

Moreover, attaching the path attribute to the method in order to create one source of truth (the swagger spec) for the events mechanism (no need to dig in the implementation to check the path and to change it manually when changed in the spec). In the method template it will look like this:

...
{{&className}}.prototype.{{&methodName}}.path = '{{&path}}';

And the above example will be like this:

var api = new API();

api.$on($scope, api.getToken.path, function (token) {
    api.setToken(token);
});

api.getToken().then(function (data) {
    ...
    api.$broadcast(api.getToken.path, data.token);
    ...
}, function (err) { ... });

What do you think ? sound reasonable ?

Boris :)