Skip to content

Instantly share code, notes, and snippets.

View antondevv's full-sized avatar

Anton Franzen antondevv

View GitHub Profile
@antondevv
antondevv / async.js
Last active February 9, 2022 20:05
async await
const asyncFunc = async () => {
const data = await fetchData()
const userData = await fetchUserData(data)
updateUserState(userData)
return
}
@antondevv
antondevv / psudoasync.js
Created February 9, 2022 19:56
psudo async
const data = fetchData()
const userData = fetchUserData(data)
updateUserState(userData)
@antondevv
antondevv / fetching.js
Created February 9, 2022 19:56
fetching
fetchData().then((data) => {
fetchUserData(data).then((userData) => {
updateUserState(userData)
})
})
@antondevv
antondevv / promise-chaining.js
Last active February 9, 2022 19:49
Chaining
const myPromise = new Promise((resolve, reject) => {
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(res => res.json().then((json) => resolve(json)))
})
myPromise.then((res) => doSomething(res)).then(() => console.log("Okey now i'm done!"))
@antondevv
antondevv / fetch.js
Created February 9, 2022 19:35
fetch with promise
const myPromise = new Promise((resolve, reject) => {
fetch('url').then(res => res.json().then((json) => resolve(json)))
})
myPromise.then(res => console.log(res)) // json data
@antondevv
antondevv / promise.js
Last active February 9, 2022 19:31
promise
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("I'm resolved")
}, 3000)
})
myPromise.then(res => console.log(res)) // I'm resolved
@antondevv
antondevv / includes.js
Created February 9, 2022 14:43
included
const doesIncludeFlorida = userDetails[0].includes('Florida') // true
@antondevv
antondevv / filter.js
Created February 9, 2022 14:37
filter
const filteredUser = allUsers().filter(user => user.state !== 'Florida')
@antondevv
antondevv / ec6-5.js
Last active February 20, 2022 19:31
arr
const getUser = (userData) => {
const [ name, surName, country, state, joined, age ] = userData.split(',')
return { name, surName, country, state, joined, age }
}
const allUsers = (users) => {
// forEach...
const user = getUser(users[0])
return [user] //returning array so we can filter, map etc..
}
allUsers(['John,Doe,USA,Florida,1995,50'])
const [ name, surName, country, state, joined, age ] = userDetails.split(',')
return { name, surName, country, state, joined, age }
// {name: "John", surName: "Doe", country: "USA", state: "Florida", joined: "1995", age: "50"}