Giter VIP home page Giter VIP logo

Comments (18)

optikalefx avatar optikalefx commented on September 15, 2024 1

I highly recommend adding device ready to the docs for this. It's the #1 thing people do with this. I would also recommend adding the list of possible cordova events on the bottom of that md page.

from corber.

alexblom avatar alexblom commented on September 15, 2024

reproduced on my side. assigning @anulman

from corber.

anulman avatar anulman commented on September 15, 2024

Broken in isleofcode/ember-cordova@38ed4fa

Working on a patch now; will post thoughts re: next steps once pushed

from corber.

anulman avatar anulman commented on September 15, 2024

Right now, there are 3 ways to subscribe to ember-cordova events: object.on(...), subscribe(), and onCordova: {...} registrations.

Implementations look something like:

import Ember from 'ember';
import EmberCordovaEventsMixin from 'ember-cordova/mixins/events';

import subscribe from 'ember-cordova/utils/subscribe';

const {
  Route,
  inject,
  on
} = Ember;

export default Route.extend(
  EmberCordovaEventsMixin, {

  cordova: inject.service('cordova'),

  beforeModel() {
    // fires
    this.get('cordova').on('deviceready', function() {
      console.log('object.on');
    });
  },

  // does not fire (injected service availability)
  didFire: on('cordova.deviceready', function() {
    console.log('Ember.on');
  }),

  // fires
  didSubscribe: subscribe('cordova.deviceready', function() {
    console.log('subscribe');
  }),

  onCordova: {
    // fires
    deviceready: function() {
      console.log('onCordova');
    }
  }
});

I think we should explicitly favour the subscribe(...) form, as it better fits with the trend toward generator functions.

@optikalefx how are you consuming deviceready?

If we decide to coalesce toward subscribe, I'll add a deprecation notice for the onCordova form to the PR, or quickly open a new one if already merged.

from corber.

optikalefx avatar optikalefx commented on September 15, 2024

In the application route

onCordova: {
    deviceready: 'deviceready'
},
deviceready() { ... }

I'm not sure what feels right on this one. I feel like ember-evented exists, so I wonder why you need to introduce your own pub/sub. I think something as necessary as deviceready shouldn't require this additional import to work.

But maybe i'm not aware of all the events needing to take place. I would think that you would just do on('event') just like any other event. Without an extra paradigm needed.

from corber.

runspired avatar runspired commented on September 15, 2024

On event has never worked because that's not how ember evented works

from corber.

optikalefx avatar optikalefx commented on September 15, 2024

? According to http://emberjs.com/api/classes/Ember.Evented.html you can trigger any named event, and then on to subscribe to it. If cordova service extended evented couldn't you have this.get('cordova').on('deviceready'); internally it would have done this.trigger('deviceready');

from corber.

runspired avatar runspired commented on September 15, 2024

@optikalefx It seems you're starting to see the difference in your comment but haven't quite grasped why subscribe exists.

Pulling from the example above:

import Ember from 'ember';
import subscribe from 'ember-cordova/utils/subscribe';

const {
  Route,
  inject,
  on
} = Ember;

export default Route.extend({
  cordova: inject.service('cordova'),

  // does not fire (injected service availability)
  didFire: on('cordova.deviceready', function() {
    console.log('Ember.on');
  }),

  // fires
  didSubscribe: subscribe('cordova.deviceready', function() {
    console.log('subscribe');
  })
});

The Cordova service does implement Evented. The thing to note here is that the reason on('cordova.deviceReady' does not work is because this is not within the same object, and on will not follow paths longer than one segment. I wrote subscribe to allow for following paths of two segments with guaranteed cleanup so that we can avoid writing the following code.

import Ember from 'ember';

const {
  Route,
  inject
} = Ember;

export default Route.extend({
  cordova: inject.service('cordova'),

  init() {
    this._super();
    this.get('cordova').on('deviceReady', this, this._readyHandler);
  },

  _readyHandler() { console.log('on fired'); },

  willDestroy() {
    this._super();
    this.get('cordova').off('deviceReady', this, this._readyHandler);
  }
});

from corber.

anulman avatar anulman commented on September 15, 2024

Thanks for posting the details @runspired. @optikalefx this is what I was referencing w/ // does not fire (injected service availability) in the original snippet.

subscribe is my preferred form as it better matches Evented's on, and will offer an easier migration if / when the generic Ember.on supports injected deps.

Seems that's where the conversation's moved, so I'm going to add a deprecation notice to the onCordova form (which predates availability of the subscribe util).

from corber.

alexblom avatar alexblom commented on September 15, 2024

Yes deprecation notice works for me. I'll include it in the next release
which also includes the live reload changes.

On Sunday, 31 July 2016, Aidan Nulman [email protected] wrote:

Thanks for posting the details @runspired https://github.com/runspired.
@optikalefx https://github.com/optikalefx this is what I was
referencing w/ // does not fire (injected service availability) in the
original snippet.

subscribe is my preferred form as it better matches Evented's on, and
will offer an easier migration if / when the generic Ember.on supports
injected deps.

Seems that's where the conversation's moved, so I'm going to add a
deprecation notice to the onCordova form (which predates availability of
the subscribe util).


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/isleofcode/ember-cordova/issues/83#issuecomment-236441319,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAPEciHiWcJn1NQgB3w63fVq351-woQyks5qbNM1gaJpZM4JUb9z
.

@alexblom http://www.twitter.com/alexblom
647 704 5272
http://www.alexblom.com

from corber.

anulman avatar anulman commented on September 15, 2024

Deprecation notice added & docs updated in d20bb28

For clarity, both the onCordova and subscribe forms were borked by the fixed commit

from corber.

alexblom avatar alexblom commented on September 15, 2024

Just an update, pr #90 by anulman fixes this. We're just waiting for a documentation fix and it will be merged/released. Thanks.

from corber.

and2 avatar and2 commented on September 15, 2024

Hi, any idea why the events might not be firing at all? I'm using the subscribe function and tried deviceready and a few other events and none are firing.

didSubscribe: subscribe('cordova.deviceready', function() { console.log('ready'); })

I'm on
Ember CLI 2.7.0
Cordova 6.3.0

from corber.

anulman avatar anulman commented on September 15, 2024

Thanks for the report @and2, will definitely look into this. Two dumb questions in the interim:

  • what version of ember-cordova?
  • can you provide the context around which didSubscribe is invoked? e.g. is it invoked at the top-level of the exported object, in a lifecycle hook, etc.

from corber.

and2 avatar and2 commented on September 15, 2024

Hey, @anulman, tried it at the top-level of a route as per existing docs. With ember-cordova 0.2.0.

import Ember from 'ember';
import subscribe from 'ember-cordova/utils/subscribe';

const { Route } = Ember;

export default Route.extend({

  cordova: Ember.inject.service(),

  didSubscribe: subscribe('cordova.deviceready', function() {
    console.log('ready');
  })

});

from corber.

and2 avatar and2 commented on September 15, 2024

Ok, I believe the issue is actually with live reaload. Running the app without it from index.html triggers all the events as expected. Once <allow-navigation href="*" /> is added in config.xml and live reload with ember cdv:serve switches to the local IP, the events are lost.

from corber.

anulman avatar anulman commented on September 15, 2024

Ah! That could be it. Your snippet looks great :)

@and2 want to create an issue for this, vs. reopen this one?

from corber.

and2 avatar and2 commented on September 15, 2024

Hey @anulman, I'll open a new one, think the problem is with how cordova.js is built. With live reload on I get an empty file with:

No-op script for when serving to both browser and Cordova device.

from corber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.