Skip to content

Instantly share code, notes, and snippets.

View antondevv's full-sized avatar

Anton Franzen antondevv

View GitHub Profile
export const changeUsersName = (name) => {
return {
type: "CHANGEUSERNAME",
payload: name,
};
};
@antondevv
antondevv / reducer.js
Last active April 2, 2022 12:38
reducer
const inititalState = { name: "User 1", age: 23 };
const addUserReducer = (state = inititalState, action) => {
switch (action.type) {
case "CHANGEUSERNAME": {
return { ...state, name: action.payload };
}
case "CHANGEAGE": {
return { ...state, age: action.payload };
}
}
@antondevv
antondevv / reducer.js
Last active April 2, 2022 12:35
reducer
const inititalState = { name: "User 1", age: 23 };
const userReducer = (state = inititalState, action) => {
switch (action.type) {
case "CHANGEUSERNAME": {
return { ...state, name: action.payload };
}
}
return state;
};
export default userReducer;
@antondevv
antondevv / index.js
Created February 20, 2022 18:35
index
import hello from './hello.js'
console.log(hello())
@antondevv
antondevv / hello.js
Created February 20, 2022 18:33
hello
export default () => {
return "Hello World!"
}
@antondevv
antondevv / domacceess.js
Created February 16, 2022 22:30
domacceess
const h1 = document.getQuerySelector('h1).innerHTML = "New text for the H1 element"
@antondevv
antondevv / promiseall.js
Created February 15, 2022 18:42
Promise chain
const myPromises = urls.map((url) => fetch(url).then((res) => res.json()));
Promise.all(myPromises).then((data) => {
// When all requests have finished
});
@antondevv
antondevv / promises.js
Created February 13, 2022 14:13
promises
setTimeout(() => {
console.log("Using callback queue")
}, 0)
new Promise(resolve => resolve(console.log("Using micro queue")))
@antondevv
antondevv / callbackhell.js
Created February 12, 2022 17:03
callback hell
const user = new XMLHttpRequest();
user.open("GET", "/user");
user.send();
user.onload = () => {
const getPosts = new XMLHttpRequest();
getPosts.open("GET", `/posts${user.response.id}`);
getPosts.send();
getPosts.onload = () => {
@antondevv
antondevv / request.js
Created February 12, 2022 16:17
old request
function reqListener () {
alert(this.responseText)
}
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", reqListener);
oReq.open("GET", "https://jsonplaceholder.typicode.com/todos/1");
oReq.send();