Practical Application Development with AppRun by Yiyi Sun

Practical Application Development with AppRun by Yiyi Sun

Author:Yiyi Sun
Language: eng
Format: epub
ISBN: 9781484240694
Publisher: Apress


The stories posted to Hacker News are categorized as Top, New, Best, Show, Ask, and Jobs. The story list of each category has the Firebase database reference. We can get the Firebase database reference of the story list (line 5). Also, we can get the Firebase database reference of the story detail (line 6).

The Story List

The Firebase story list reference publishes the value event with an array of at most 500 story IDs when the application connects to Firebase; in addition, the story list has updates at the server side. We can create the getList function to subscribe to the value event to get the story IDs (Listing 6-7).1. export const getList = (category, min, max) => {

2. const ref = db.child(`${category}stories`);

3. ref.on('value', async snapshot => {

4. const items = await Promise.all(snapshot.val().map((id, idx) =>

5. (idx >= min && idx < max && (typeof id === 'number')) ?

6. fetchJSON(`item/${id}`) : id

7. ));

8. app.run('refresh', category, { min, max, items });

9. });

10. };



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.