Skip to content

Instantly share code, notes, and snippets.

View mattisa's full-sized avatar

Matti Suur-Askola mattisa

View GitHub Profile
export default function debouncePromise(fn, delay) {
let time = null;
return (...args) => {
if (time) {
clearTimeout(time);
}
return new Promise((res, rej) => {
time = setTimeout(() => {
fn.apply(null, args)
.then((...resArgs) => res.apply(null, resArgs))
@mattisa
mattisa / bindValue.ts
Created February 8, 2020 20:30
Simpe value binder before memoized return values
import { get, set, isEqual } from 'lodash';
import deepClone from 'clone-deep';
const defaultOpts = {
parseValue: (v: any) => v,
parseState: (v: any) => v,
valueFn: 'value',
onChangeFn: 'onChange'
};
@mattisa
mattisa / index.js
Last active March 20, 2017 12:22
Simple calculator with function chaining
const plus = (a, b) => a + b;
const minus = (a, b) => a - b;
const multiply = (a, b) => a * b;
const divide = (a, b) => a / b;
const Calc = (a) => ({
plus: (...b) => Calc(b.reduce(plus, a)),
minus: (...b) => Calc(b.reduce(minus, a)),
multiply: (...b) => Calc(b.reduce(multiply, a)),
divide: (...b) => Calc(b.reduce(divide, a)),
@mattisa
mattisa / index.ts
Last active February 6, 2017 10:28
Sample to chain async calls
import seeder from './seeder';
seeder({ model: 'User' })
.clear()
.seed()
.fail()
.clear()
.catch((err:Error) => {
console.log( err.stack )
console.error('chain catch');
@mattisa
mattisa / diff_helper.ts
Created March 20, 2016 12:54
Get nested json diff. this is just initial version to store for later use.
module helpers {
'use strict';
export class DiffHelper {
public diff(a, b, seed = {}) {
const keys = this.arrayUnique(Object.keys(a).concat(Object.keys(b)));