Radio icon indicating copy to clipboard operation
Radio copied to clipboard

make subscribe with context less error prone

Open mwaschkowski opened this issue 10 years ago • 5 comments

Hi,

A number of times now I've done stuff like this:

radio(constant.SHOW_CLIENT_APPLICATION).subscribe(this.xyz, this);

instead of this:

radio(constant.SHOW_CLIENT_APPLICATION).subscribe([this.xyz, this]);

Would you please create a new method/alias to prevent this kind of thing? Maybe something like:

radio(constant.SHOW_CLIENT_APPLICATION).subscribe(this.xyz).context(this);

I know its minor, but its a big problem when you first run into this as there are no error/indications to help out.

Thank you,

Mark

mwaschkowski avatar Jun 13 '14 15:06 mwaschkowski

Yeah, I look at it now and I agree that pattern of using an array was array odd and I would be open to changing it. Personally, I don't really use context and just simply use a bind method.

IE: radio(CHANNEL).subscribe(angular.bind(this, this.mymethod);

uxder avatar May 22 '15 22:05 uxder

Ah, I see. I don't use angular, so don't have the bind method available. I would just make a different method name that took the two parameters. subscribeBind(x, y) maybe?

Regards,

Mark

On Fri, May 22, 2015 at 6:20 PM, Scott (Tomoharu) Murphy < [email protected]> wrote:

Yeah, I look at it now and I agree that pattern of using an array was array odd and I would be open to changing it. Personally, I don't really use context and just simply use a bind method.

IE: radio(CHANNEL).subscribe(angular.bind(this, this.mymethod);

— Reply to this email directly or view it on GitHub https://github.com/uxder/Radio/issues/12#issuecomment-104788249.

mwaschkowski avatar May 23 '15 11:05 mwaschkowski

Angular was just an example but Bind is available in ES5 so if you just need to support IE9 and up, it is natively available already. http://itsnull.com/articles/start-using-es5/ (check Function.prototype.bind). If you need to support older browsers, there are plenty of bind solutions like lowdash/underscore e.t.c.

For radio and making it better, I think we can just keep it simple and an provide an alternative to that .subscribe([method, context]) and make the following available:

radio(constant.SHOW_CLIENT_APPLICATION).subscribe(this.xyz, this);

which is much more natural.

uxder avatar May 23 '15 21:05 uxder

Yes, sounds good!

Mark

On Sat, May 23, 2015 at 5:34 PM, Scott (Tomoharu) Murphy < [email protected]> wrote:

Angular was just an example but Bind is available in ES5 so if you just need to support IE9 and up, it is natively available already. http://itsnull.com/articles/start-using-es5/ (check Function.prototype.bind). If you need to support older browsers, there are plenty of bind solutions like lowdash/underscore e.t.c.

For radio and making it better, I think we can just keep it simple and an provide an alternative to that .subscribe([method, context]) and make the following available:

radio(constant.SHOW_CLIENT_APPLICATION).subscribe(this.xyz, this);

which is much more natural.

— Reply to this email directly or view it on GitHub https://github.com/uxder/Radio/issues/12#issuecomment-104946106.

mwaschkowski avatar May 24 '15 00:05 mwaschkowski

Okay, will try to find time for this sometime. But if you have time, feel free to tackle it as well.

uxder avatar May 24 '15 19:05 uxder