Skip to content
This repository was archived by the owner on Apr 2, 2018. It is now read-only.
This repository was archived by the owner on Apr 2, 2018. It is now read-only.

Investigate Observables #4

Closed
Closed

Description

@imhoffd

As suggested in #1 (comment), and similar to ionic-team/legacy-ionic-cloud#4, the cloud client should somehow provide observable streams to events such as "is the user logged in" and "push notification received."

Investigate how this would be done and discuss options.

@cklanac @tlancina

Activity

  1. self-assigned this
    on Jul 1, 2016
  2. justinschuldt commented on Jul 28, 2016

    @justinschuldt

    Here is our use case for push notification observables.

    We have a couple different cases for what to do when a notification is received:
    New message for the user - go to the message details page and load the message
    New update available (via Deploy) - update and then close the app
    Silent notification - do some background stuff, download new stuff, etc

    I'd like to have multiple subscribers to the stream so that the business logic for a feature can be contained in its component(s). For example all the logic to determine if an update should be downloaded and extracted should be contained in the DeployService, all the logic to navigate to and show a new message should be in the MessagePage class.

    I'd like to avoid having a bunch of business logic and dependencies where the Push.init happens like:

    push.on('notification', data => {
      if (data.additionalData.messageId) {
        nav.push(MessagePage, {id: data.additionalData.messageId});
      } else if (data.additionalData.deploy === true) {
        DeployService.update();
      } else if (newFeature) (
        // bunch of logic
      } else {
        // do some background stuff
      }
    });

    Right now I've written a class (PushService) that inits the push plugin and returns observables that I consume like this:

    import {NavController} from 'ionic-angular';
    import {Component} from '@angular/core';
    
    import {AzureService} from '../../shared';
    import {MessagePage} from '../../dashboard';
    import {PushService} from './';
    import {Observable} from 'rxjs/Observable';
    
    @Component({
        templateUrl: 'build/shared/native/native.html',
        providers: [PushService]
    })
    export class NativePage {
        constructor(
            private nav: NavController,
            private azureService: AzureService,
            private pushService: PushService
        ) {
    
            this.pushService.notification()
                .subscribe(
                    data => {
                        console.debug('subscribed data: ', data);
                        azureService.api('pushRecieved').post(data);
                        if (data && data.additionalData && data.additionalData.messagesId)
                            nav.push(MessagePage, {id: data.additionalData.messagesId});
                    }
                );
        }
    
        // Push
        register(): void {
            this.pushService.register();
        }
    }

    Right now my PushService is doing the observable wrapping, but I think that wrapping should happen at a lower level. Maybe Ionic Native should included the observable wrapper?

    tl;dr Observables would be cool, but I think it should be done at the plugin level for push notifications.

    Let me know what you think!

  3. imhoffd commented on Aug 23, 2016

    @imhoffd
    ContributorAuthor

    @justinschuldt Can I have you update and test observable support for push notifications? (FYI there are breaking changes.) I only did it for push notifications because I'd like you to validate my approach.

    import { Push } from '@ionic/cloud-angular';
    this.push.rx.notification()
      .subscribe((msg) => {
        console.log('OBSERVABLE got notification!', msg);
      });

    I was able to use filter() on a deploy flag to simulate one of your use cases.

    Check it out: https://github.com/driftyco/ionic-cloud-angular/blob/master/src/index.ts#L21-L38

    You may notice there's no support for dispose yet. I'm waiting on an issue whose URL I left in the comment.

    Likes/dislikes?

  4. imhoffd commented on Aug 23, 2016

    @imhoffd
    ContributorAuthor

    What other observables might be suited in the Cloud Client? I know it would be nice to subscribe to a deploy channel, but the deploy plugin doesn't let us push out changes (we'd have to poll).

  5. justinschuldt commented on Aug 31, 2016

    @justinschuldt

    Hey, sorry it's taken me a while to get to this.

    Reading through it, it looks great. I'm going to spin up a new app with the cloud client and test it out this weekend.

    I've been testing my push-plugin wrapper service in different app states, and have gotten some inconsistent behavior when the app is dead. My criteria has been that when the phone receives a notification, it is able to send an http request.

    I'll test yours in the same conditions and let you know what I find!

  6. justinschuldt commented on Aug 31, 2016

    @justinschuldt

    As far as observables for other parts of the cloud client, I'm not sure an observable deploy service would be very valuable to most people. I cant think of a realistic situation where I would want to watch for updates that vigilantly.

    it could be cool to see analytics in real time, but that wouldn't be needed in the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions