ionic-team / ng-cordova

OBSOLETE: Please move to Ionic Native https://github.com/ionic-team/ionic-native
https://github.com/ionic-team/ionic-native
MIT License
3.48k stars 1.05k forks source link

web dev strategy #10

Open revolunet opened 10 years ago

revolunet commented 10 years ago

Hey Very cool initiative guys, thanks :)

Do you plan to offer a solution to override the cordova calls while not in cordova context ? For example, while developing in chrome it would be cool to have a standard way to provide mocks, for example for the ContactApi.

I'd be pleased to help :)

mlynch commented 10 years ago

That's a damn good idea! I'd love to hear your ideas/code on that.

revolunet commented 10 years ago

I have a simple (naive?) approach :

angular.module('app', [
    'ngCordova',
    'ngCordova.mocks.contacts',
    'ngCordova.mocks.accelerometer'
]
$mock.when('$cordovaCamera','getPicture',['profile']).inject(function(){
    return 'img/test/face.png';
});
revolunet commented 10 years ago

On a similar idea, but that's another project, would be to create a kind of "proxy" that relays the cordova calls to your real device, so you can have real device data and behaviour right into your chrome :)

yrezgui commented 10 years ago

@revolunet The idea of mock custom data is the best. I really like it.

calendee commented 10 years ago

Came looking through issues to post a similar request. Would really love to mock data for desktop testing. Right now, need to put each $cordovaXX in a service and wrap cordova detection around them. Pretty painful.

AgDude commented 10 years ago

I agree, this would be great functionality to have.

@calendee, in the mean time here is a solution using a decorator, which is a little less painful than individual services.

.config(function($provide){
    // Wrappers for ngCordova so it doesn't throw errors in the browser

    var cordovaCheck = function($delegate, prop){
      //This function will check if cordova is present, and if not, set the prop of $delegate to noop
      if ( angular.isUndefined(window.cordova) ){
        $delegate[prop] = angular.noop;
      }
      return $delegate;
    };

    $provide.decorator( '$cordovaDevice', function($delegate){
      return cordovaCheck($delegate, 'getUUID')
    });

    $provide.decorator( '$cordovaSplashscreen', function($delegate){
      return cordovaCheck($delegate, 'hide')
    });

  })
mrzmyr commented 9 years ago

I posted my idea in #307