This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import firebase from 'react-native-firebase' | |
const config = { | |
apiKey: "AIzaSyBiXJTuUD5Ya9PUM81l5qQ83bOZIAlvIGE", | |
authDomain: "react-native-73f21.firebaseapp.com", | |
databaseURL: "https://react-native-73f21.firebaseio.com", | |
projectId: "react-native-73f21", | |
storageBucket: "react-native-73f21.appspot.com", | |
messagingSenderId: "150783570753" | |
}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": 64833, | |
"productName": "Sleek Steel Mouse", | |
"price": 4520000, | |
"productDescription": "Dolores distinctio labore necessitatibus iste voluptatem repudiandae repellendus. Sit voluptas dicta nisi et consequuntur. Dolores a quia atque molestias. Eligendi excepturi consectetur maiores ea dolores minima repellendus dolores omnis. Nulla nam eius odio repellendus itaque magni.\n \rPariatur accusantium maxime aut et vel earum repellendus perspiciatis incidunt. Sed debitis est et odio adipisci eum est beatae quam. Voluptatem sint esse. Fuga sapiente nam. Ut veritatis incidunt rerum amet dolores culpa. Exercitationem maiores autem accusantium sint consequatur et et.\n \rQui eos aut iure aut reprehenderit at excepturi dolor distinctio. Omnis rem nulla. Vitae ut molestias aut nihil vel ut ipsam. Qui omnis sit qui fugit quia praesentium quia ad facilis.", | |
"image": "http://lorempixel.com/340/280/food/1" | |
}, | |
{ | |
"id": 98125, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { StyleSheet, Text, View,Dimensions } from 'react-native' | |
const dim = Dimensions.get('screen') | |
export default class App extends React.Component { | |
state = { | |
screenWidth:dim.width, | |
screenHeight:dim.height, | |
orientation:this._getOrientation(dim.width,dim.height) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Promise((resolve, reject) => { | |
reject('reject') | |
console.log('ALWAYS REACHED') | |
}).then(() => console.log("RESOLVED")) | |
.catch(() => console.log("REJECTED")); | |
new Promise((resolve, reject) => { | |
throw('err') | |
console.log('NEVER REACH') | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Anonymous Async Function | |
let main = (async function() { | |
let value = await doAsync(); | |
})(); | |
// 2. Async Function Declaration | |
let main = async function() { | |
let value = await doAsync(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const firstPromise= () => (new Promise((resolve,reject) => { | |
setTimeout(() =>{ resolve('first Promise')},1000) | |
})) | |
const secondPromise = () => ( new Promise((resolve,reject) =>{ | |
setTimeout(() =>{ resolve('second Promise')},1000) | |
})) | |
const thirdPromise = () => ( new Promise((resolve,reject) =>{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function fetchWithAsyncAwait (id) { | |
try { | |
let response = await fetch(endpoint + id) | |
response = await response.json() | |
console.log(response) | |
} catch (error) { | |
console.log('opps' + error) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Promise */ | |
const endpoint ='https://jsonplaceholder.typicode.com/users/' | |
function fetchWithPromise (id) { | |
fetch(endpoint + id) | |
.then(response => { | |
return response.json(); | |
}) | |
.then(user => { | |
console.log(user); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const doFetch = (url) => fetch(url).then(result => result.json()) | |
let urls =[ | |
'https://jsonplaceholder.typicode.com/posts/1', | |
'https://jsonplaceholder.typicode.com/posts/2', | |
'https://jsonplaceholder.typicode.com/posts/3', | |
'https://jsonplaceholder.typicode.com/posts/4', | |
] | |
let promises=[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.seriousRace = function(promises) { | |
let indexPromises = promises.map((p, index) => p.catch(() => {throw index})) | |
return Promise.race(indexPromises).catch(index => { | |
let p = promises.splice(index, 1)[0] | |
p.catch(e => console.log( e + ' terjatuh,ahh sudahlah lanjutkan saja')) | |
return Promise.seriousRace(promises) | |
}) | |
} | |
let peserta1 = new Promise(resolve => setTimeout(resolve, 30, 'Peserta 1')) |