Use async/await with TypeScript in Cloud Functions for Firebase - Firecasts

Поділитися
Вставка
  • Опубліковано 17 січ 2025

КОМЕНТАРІ • 63

  • @codinginflow
    @codinginflow 4 роки тому +5

    This video solves exactly the questions I was having lol. Great work

  • @sveinsoermo9883
    @sveinsoermo9883 6 років тому +12

    Very, very good video series. HIGH QUALITY, right on target!

  • @yogenp
    @yogenp 6 років тому +4

    3.47 onwards is what I was looking for. Thank you, Doug.

  • @SonnySangha
    @SonnySangha 6 років тому +9

    Firebase + Typescript 🔥

  • @cindysi63
    @cindysi63 6 років тому +4

    Wow. Nicely explained. I finally get it now. I like the refactoring part. Thank you.

  • @rammalvarez2664
    @rammalvarez2664 6 років тому +4

    That's super nice, the code looks a lot cleaner, thanks for the tip!

  • @SamBecker1
    @SamBecker1 5 років тому +1

    This is a great video. And an area where TypeScript adds a lot of clarity to the development process.

  • @danvilela
    @danvilela 4 роки тому

    Loving these series! I had some doubts with Promises, now i know what i needed :) Thanks!

  • @akXIII
    @akXIII 6 років тому

    Just wanted to say thanks! This was a very helpful series

  • @saramandavid1596
    @saramandavid1596 4 роки тому

    It's really clear and useful. Save a lot of time for beginners like me.

  • @noamgonen6243
    @noamgonen6243 6 років тому +2

    Thanks for the video Doug. Good to see you're back from your Google Tel-Aviv improvised office, although your view there was better looking than the green screen backdrop :-)

    • @dougstevenson3769
      @dougstevenson3769 6 років тому +2

      Maybe future firecasts should appear to come from exotic locations all over the world!

    • @noamgonen6243
      @noamgonen6243 6 років тому +1

      For whatever it counts, I'm up for Async/await pt.3 from Bora Bora? Shall I start gofundme 2 cover the trip?

    • @dougstevenson3769
      @dougstevenson3769 6 років тому +2

      I'm not one to turn down free money.

  • @JOKBO1
    @JOKBO1 6 років тому

    Awesome video! Exactly what I needed today to refactor some code. Keep these up

  • @patricknasc
    @patricknasc 4 роки тому

    Thank you Doug! I digged a lot your playlist!

  • @postfixnotation9829
    @postfixnotation9829 4 роки тому

    This video series helped me a lot! Thank you!!!

  • @jairorudas2889
    @jairorudas2889 5 років тому

    amazing explanation! Congratulation!! and Thank you very much!

  • @eduardooviedoblanco6514
    @eduardooviedoblanco6514 6 років тому +1

    How do you deal with the "snapshot.forEach" as specified in the documentation, because I am having problems with async await using that.

  • @jw_fingerstyle
    @jw_fingerstyle 3 роки тому

    incredibly educating video.

  • @jlb861
    @jlb861 6 років тому +3

    When I do this I get red underlines in the editor when trying to access anything after snapshot.data(). I get an "Object is possibly 'undefined'" error. What am I doing wrong? Code and data structure is identical.

    • @sapir9480
      @sapir9480 4 роки тому

      to ignore errors like ' Object is possibly 'undefined'.' :
      go to tsconfig.json and add "strictNullChecks":false
      * credit to a comment of ralbertini on github *

    • @mirkoson
      @mirkoson 2 роки тому

      It will be enough to use null coalescing, like this: areaSnapshot.data()?.cities

  • @duncanhunter9025
    @duncanhunter9025 6 років тому +4

    Awesome teacher!

  • @lgopt7467
    @lgopt7467 6 років тому +2

    Once again, absolutely brilliant! And very appreciative that you delivered on the time you committed. Admirable!!
    But i still have 1 nagging problem. Inside my forEach there are processes where I need to use AWAIT. So, I made the forEach async. But it doesn't run more than once. Some say use "await Promise.all' with snapshot.map(...).
    What's your best advice on handling a snapshot.forEach loop when there are AWAIT promises in every iteration?

    • @dougstevenson3769
      @dougstevenson3769 6 років тому +2

      Do you really need to wait for each one in sequence, or can you do them all in parallel like my example? If you must wait for each one separately, try switching to a for loop (or something that doesn't take a lambda function as a callback).
      stackoverflow.com/questions/37576685/using-async-await-with-a-foreach-loop

    • @lgopt7467
      @lgopt7467 6 років тому +3

      Thanks bro, you're a true Gem!
      Ok, loads of reading & trying stuff out... Will let you know what worked best.
      Thanks a million again :-)

  • @KyoKurosagi
    @KyoKurosagi 6 років тому +3

    How is the javascript? cause currently I can't use async/await for javascript in cloud functions.

    • @dougstevenson3769
      @dougstevenson3769 6 років тому +1

      Cloud Functions currently runs node 6, which does not support ECMAScript 2017 async/await, which means you can't use it in JavaScript. When the runtime is upgraded to node 8, you will be able to. I don't know when that will be. For now, you have to use a transpiler.

    • @KyoKurosagi
      @KyoKurosagi 6 років тому

      thanks for the reply, I'm currently migrating from javascript to typescript in order to use async/await.
      just an issue not related to this post, I think.
      I need to delete multiple data as link below, but it only provide node.js code not in typescript.
      is it not necessary to use process.nextTick (only can use in javascript) anymore?
      With async/await, is it already solve the stack problem?
      firebase.google.com/docs/firestore/manage-data/delete-data

    • @dougstevenson3769
      @dougstevenson3769 6 років тому

      If you have a programming question, I think it would be better to ask on Stack Overflow.

    • @KyoKurosagi
      @KyoKurosagi 6 років тому

      ok

  • @rajarams8560
    @rajarams8560 6 років тому

    video tips using async/await for realtime database transaction also for firestore runTransaction in cloud functions.

  • @krivoviajes
    @krivoviajes 3 роки тому

    Gracias amigo!!!

  • @raghav4296
    @raghav4296 5 років тому

    Hi Doug, some of the functions samples (like the audio ffmpeg conversion) still has the .js examples. Are there any plans to revamp the github examples to reflect .ts? Many thanks.

  • @thequizclassroom
    @thequizclassroom 6 років тому +1

    thanks, very useful

  • @sveinsoermo9883
    @sveinsoermo9883 6 років тому

    BTW..forgot... PLS, more of the same! Also hope you can do an extensive and in depth on Firestore rules. I know there is some available..but..:-)..and as U say...Firestore/base there are NO substitutes...

  • @myyellowdog
    @myyellowdog 6 років тому +1

    Any advice on using async/await with batched transactions via firestore.runTransaction( transaction => {...} )? I've been trying to figure this out, but my head is about to explode. Thanks in advance if you have time to help!
    Great video, btw! I have learned a lot watching this and your previous videos.

    • @dougstevenson3769
      @dougstevenson3769 6 років тому

      It sounds like you might want to post your question to Stack Overflow so you have more space to explain in more detail what problem you're running into.

    • @myyellowdog
      @myyellowdog 6 років тому

      Thanks for the quick response. I actually just got it working! Still testing, though, so I may still have to go the Stack Overflow route. Wish me luck!

    • @amitk.512
      @amitk.512 6 років тому +1

      You might find what you are looking for in the following link
      rnfirebase.io/docs/v4.0.x/firestore/transactions
      A little late but hope this helps others

  • @wwgg1139
    @wwgg1139 3 роки тому

    Why would one use async/await vs then().catch()? Isn't the latter easier to test?

  • @sediavindivoh
    @sediavindivoh 4 роки тому

    Variable 'promises' implicitly has type 'any[]' in some locations where its type cannot be determined, and areaSnapshot 'Object is possibly 'undefined'. How do I fix these errors?

  • @Sarah2005u
    @Sarah2005u 4 роки тому

    Great video. From your example I tried working on an example which calls a function that returns a promise and I am trying to populate a variable but getting empty string outside of the async function.
    let DatafromPromise = {};
    const loadDataPromise = async () => {
    //async keyword added before the function, you can indicate that the function always returns a promise
    try {
    const myPromise = await getDataFromFile(
    ); // This returns a promise.
    DatafromPromise = myPromise.value;
    // When it awaits from above line I want to get the data value
    //console.log(DatafromPromise);
    // I see data here.
    } catch (error) {
    console.log(error);
    }
    };
    loadDataPromise();
    // I am a bit confused, Is this returning a promise too?
    console.log("SelectedDate " + SelectedDate);
    console.log(DatafromPromise); // this is coming out empty

  • @SampathLokuge
    @SampathLokuge 6 років тому

    Awesome. Thank you :)

  • @YousefKabbara
    @YousefKabbara 5 років тому +3

    #Error
    - "Object is possibly 'undefined'.ts(2532)" error on line 9
    - "Variable 'results' implicitly has type 'any[]' in some locations where its type cannot be determined.ts(7034)" error on line 17
    and
    - "Variable 'results' implicitly has an 'any[]' type.ts(7005)" on line 23
    Anyone have the same problem or can help?

    • @Nu1zzz
      @Nu1zzz 4 роки тому

      I have this. Did you resolved ?

  • @atmospheric_b
    @atmospheric_b 5 років тому

    nice one! Thanks

  • @surojd
    @surojd 6 років тому

    can you make onCall request of firebase cloud functions?

  • @martinflores9611
    @martinflores9611 6 років тому

    wich´s the version what you use ?

  • @hakunamata_tuh
    @hakunamata_tuh 6 років тому +2

    super!

  • @kosuel0
    @kosuel0 6 років тому

    I got an error when I declare cloud function like this:
    exports.updateFriends = functions.https.onCall(async (data, context) => {...})
    error Parsing error: Unexpected token =>
    does anybody know?

  • @michaelxieyangliu7810
    @michaelxieyangliu7810 6 років тому +1

    Great!

  • @duanehodges3146
    @duanehodges3146 5 років тому

    Can you use aync/await on .onSnapshot?

    • @dougstevenson3769
      @dougstevenson3769 5 років тому +1

      You can use async on the callback you pass to it, but onSnapshot doesn't return a promise, so you can't await it.

    • @duanehodges3146
      @duanehodges3146 5 років тому

      @@dougstevenson3769 I need to filter the items from onSnapshot and remove duplicate items after it's finished. What would be a good strategy for that?

  • @РусланЕгоров-ж8е
    @РусланЕгоров-ж8е 6 років тому +1

    You should probably use Array.prototype.map at 5:08

    • @dougstevenson3769
      @dougstevenson3769 6 років тому +2

      The examples are kept simple here because many people following these tutorials have little to no JavaScript or functional programming experience, coming from Android or iOS backgrounds. For anyone who understands loops, foreach needs no explanation. But I can't say the same about map. :-(

    • @РусланЕгоров-ж8е
      @РусланЕгоров-ж8е 6 років тому

      Okay then :-)

  • @robe0072009
    @robe0072009 6 років тому +1

    Nice !

  • @enigmasdelmundo5833
    @enigmasdelmundo5833 5 років тому

    Easier is impossible !