Skip to content

Instantly share code, notes, and snippets.

View ladas-larry's full-sized avatar

Ladislav M. ladas-larry

View GitHub Profile
@mvbattan
mvbattan / reducer.js
Last active June 4, 2018 15:29
Reducer description
const reducerDescription = {
[actions.GET_MATCHES]: (state, action) => ({ ...state, matchesLoading: true }),
[actions.GET_MATCHES_SUCCESS]: (state, action) => ({
...state,
matchesLoading: false,
matchesError: null,
matches: action.payload
}),
[actions.GET_MATCHES_FAILURE]: (state, action) => ({
...state,
@jiayihu
jiayihu / actionCreator.ts
Last active September 20, 2019 13:10
Minimal action creator factory for redux-observable and redux-saga
import { IAction } from '../types/redux.types';
import { actionTypes as errorTypes, showError } from './errors.actions';
interface IPayloadCreators {
request(...args: any[]): any;
success(...args: any[]): any;
failure?(errorMsg: string): any;
}
interface IActionCreator {
@ustun
ustun / reducer_as_immutable_class.js
Created February 6, 2017 09:56
redux reducer from immutable class
var camelCase = require('lodash.camelcase');
const {Map, Record, List} = require('immutable');
class Todo extends Record({ description: null, completed: false }) {
toggle() {
return this.set('completed', !this.completed);
}
}
const InitialTodoApp = Record({
const original = [0,1,2,3];
const copy = Object.assign([], original, { 2: 42 }); // [0,1,42,3]
console.log(original);
// [ 0, 1, 2, 3 ]
console.log(copy);
// [ 0, 1, 42, 3 ]
@ericelliott
ericelliott / dependency-injection.js
Created October 2, 2016 01:02
Dependency Injection
const consumer = dependency => dependency.doSomething();
const realDependency = {
doSomething () {
console.log('did something!');
}
};
consumer(realDependency);
@msmfsd
msmfsd / es7-async-await.js
Last active February 4, 2024 17:38
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@graceavery
graceavery / harryPotterAliases
Last active September 20, 2024 22:13
bash aliases for Harry Potter enthusiasts
alias accio=wget
alias avadaKedavra='rm -f'
alias imperio=sudo
alias priorIncantato='echo `history |tail -n2 |head -n1` | sed "s/[0-9]* //"'
alias stupefy='sleep 5'
alias wingardiumLeviosa=mv
alias sonorus='set -v'
alias quietus='set +v'
@anvk
anvk / promises_reduce.js
Last active September 8, 2024 15:10
Sequential execution of Promises using reduce()
function asyncFunc(e) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(e), e * 1000);
});
}
const arr = [1, 2, 3];
let final = [];
function workMyCollection(arr) {
@ladas-larry
ladas-larry / parseQuery.js
Last active August 13, 2017 09:50
Parse query string
function parseQuery(locationSearch) {
locationSearch = locationSearch.substring(1); // remove "?" at the beginning
var values = locationSearch.split('&');
var queryObj = values.reduce(function (result, item) {
var parts = item.split('=');
result[decodeURIComponent(parts[0])] = parts[1];
return result;
}, {});
return queryObj;
}
@jmarceli
jmarceli / README.md
Last active October 31, 2019 09:46
React errors explained

1

You will get one of these:

Uncaught (in promise) TypeError: Cannot read property 'toUpperCase' of undefined(…)

ReactCompositeComponent.js:870 Uncaught TypeError: Cannot read property 'displayName' of undefined

if you try to: