Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events Unsubscribe with second param. #11716

Closed
Bernardoow opened this issue May 18, 2017 · 4 comments
Closed

Events Unsubscribe with second param. #11716

Bernardoow opened this issue May 18, 2017 · 4 comments

Comments

@Bernardoow
Copy link

Ionic version: (check one with "x")
[ ] 1.x
[X] 2.x
[X] 3.x

I'm submitting a ... (check one with "x")
[X] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or http://ionicworldwide.herokuapp.com/

Current behavior:

I using Events. One first page in functionionViewWillEnter I subscribe and in ionViewWillLeave I unsubscribe.

In moment when I unsubscript like this [1]Works.
But when I put like this [2]. Maybe can be a bug. I don't know.

[1] this.events.unsubscribe('pedido-acoes:atraso');
[2] this.events.unsubscribe('pedido-acoes:atraso', () => {});

Expected behavior:

I was expected this [2] unsubscribe event.

Steps to reproduce:

Related code:
this.events.unsubscribe('pedido-acoes:atraso');
this.events.unsubscribe('pedido-acoes:atraso', () => {});

Other information:

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):
Your system information:

Cordova CLI: 6.5.0
Ionic Framework Version: 3.0.1
Ionic CLI Version: 2.2.2
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v6.10.3
Xcode version: Not installed

@jgw96
Copy link
Contributor

jgw96 commented May 18, 2017

Hello, thanks for using Ionic! Could you post a plunker we could use to reproduce this issue?

@xmellado
Copy link

xmellado commented Jun 1, 2017

Hi!
@Bernardoow I think you are not using properly Ionic Events. You must subscribe and unsubscribe the very same object, as explained here or you can remove all subscribers at the same time.
IMHO, I prefer to use a shared service between the components that has one of the RxJS subject types. The source class can publish using a service function that does next on the subject, and the target class can observe the stream obtaining the subject as an observable.

Here you have an example of this kind of service:

import {Injectable} from '@angular/core';
import {Observable} from 'rxjs/Observable';
import {Subject} from 'rxjs/Subject';

import {Booking} from '../../common/model/booking';


@Injectable()
export class BookingEventsService
{
    private _newChannel: Subject<Booking> = new Subject<Booking>();


    constructor()
    {
    }

    publishNew( booking: Booking )
    {
        this._newChannel.next( booking );
    }

    newChannel(): Observable<Booking>
    {
        return this._newChannel.asObservable();
    }
}

Hope it helps. Regards,
Xavi

@jgw96
Copy link
Contributor

jgw96 commented Jun 5, 2017

Hello, all! After further review, this seems like more of a support question. Because of this, I will urge that you ask this question on our forum or on our slack channel. Thanks for using Ionic!

@jgw96 jgw96 closed this as completed Jun 5, 2017
@ionitron-bot
Copy link

ionitron-bot bot commented Sep 2, 2018

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants