chrisgriffith / ionic-native-mocks

Ionic Native Mocks are designed to be used as placeholders during development for the actual Ionic Native modules.
205 stars 42 forks source link

[DOC] Add prod / dev switch scenario #23

Open vogloblinsky opened 6 years ago

vogloblinsky commented 6 years ago

Hi,

Thanks for these useful mocks.

Could you add in the main README an explanation about how we can disable mock in production mode ?

//AOT trick
let checkDevMode = false;
if (isDevMode()) {
  checkDevMode = true;
}
const CameraConfiguration = (checkDevMode) ? { provide: Camera, useClass: CameraMock } : Camera;

providers: [
    ...,
    CameraConfiguration,
    ...
]
asofyan commented 6 years ago

I think this approach is better. You don't have to change it every time you build your app:

const isBrowser = document.URL.includes(‘https://’) || document.URL.includes(‘http://’);/*document.URL.startsWith(‘http’);

and then a bit lower in the provides :

(isBrowser ? {provide : Camera, useClass : CameraMock} : Camera),
(isBrowser ? {provide : ImagePicker, useClass : ImagePickerMock} : ImagePicker),
(isBrowser ? {provide : Geolocation, useClass : GeolocationMock} : Geolocation),
chrisgriffith commented 6 years ago

Thanks. I will add this to the Read Me shortly.

sebinpj commented 5 years ago

const isBrowser = document.URL.includes(‘https://’) || document.URL.includes(‘http://’);/*document.URL.startsWith(‘http’);

Your approach doesnt work i logged this and it always returned true . and ionic seems to be running in the localhost in a mobile device