Skip to content

Instantly share code, notes, and snippets.

@ponnex
Last active May 7, 2018 23:31
Show Gist options
  • Select an option

  • Save ponnex/9531106feb1e547dfbf2c1b158946d36 to your computer and use it in GitHub Desktop.

Select an option

Save ponnex/9531106feb1e547dfbf2c1b158946d36 to your computer and use it in GitHub Desktop.

Revisions

  1. ponnex revised this gist May 7, 2018. 1 changed file with 12 additions and 4 deletions.
    16 changes: 12 additions & 4 deletions Promise Example
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    DISCLAIMER: Did not test this code HAHAHA ask lang if ever naay error ;)

    // Camera Service
    onTakePhoto() {
    return new Promise((resolve, reject) => {
    @@ -6,9 +8,11 @@ onTakePhoto() {
    // Other Codes Here
    takePicture(options)
    .then((imageAsset: any) => {
    // Other Codes Here
    let source = new ImageSource();
    source.fromAsset(imageAsset).then((source) => {
    return resolve(source);
    });
    });
    return resolve(this.imageTaken);
    }).catch(err => {
    return reject(err);
    });
    @@ -19,8 +23,12 @@ onTakePhoto() {
    }

    // Component
    this._cameraService.onTakePhoto().then((imageAsset: ImageAsset) => {
    this.priceListImage = imageAsset; // <- the ImageAsset from Service ;)
    this.priceListImage = imageSource;

    this._cameraService.onTakePhoto().then((imageSource: ImageSource) => {
    this.priceListImage = imageSource; // <- the ImageAsset from Service ;)
    console.dir(this.priceListImage);
    //Research on how to use the ImageSource for e.g. Image src for displaying the image, get the path of the file, etc
    }).catch(err => {
    // Do something here when there's an error
    });
  2. ponnex created this gist May 7, 2018.
    26 changes: 26 additions & 0 deletions Promise Example
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    // Camera Service
    onTakePhoto() {
    return new Promise((resolve, reject) => {
    requestPermissions().then(
    () => {
    // Other Codes Here
    takePicture(options)
    .then((imageAsset: any) => {
    // Other Codes Here
    });
    return resolve(this.imageTaken);
    }).catch(err => {
    return reject(err);
    });
    },
    () => return reject(err);
    );
    });
    }

    // Component
    this._cameraService.onTakePhoto().then((imageAsset: ImageAsset) => {
    this.priceListImage = imageAsset; // <- the ImageAsset from Service ;)
    }).catch(err => {
    // Do something here when there's an error
    });