Skip to content

Instantly share code, notes, and snippets.

import {get} from 'lodash'
let x = {a: 1, b:2}
// a and b is conditional key like if key == a
let hope = get(x, 'kkk', 'not exist');
// magic is just happen not exist is appear welcome lodash
@mijms
mijms / index.js
Created July 21, 2021 13:22
apply filter
//// exporting your index applying function
import * as Filters from './main';
export default function applyFilters(params={}, data, state=store.getState(), props={}){
const action = get(Filters, params.key, (p, d)=>d);
data = action(params, data, state, {applyFilters: applyFilters, ...props});
if(params.then){
data = applyFilters(params.then, data, state, props);
}
return data;
@mijms
mijms / builder.js
Created July 21, 2021 13:10
Reducer builder function sample
export const buildReducers = (name)=>{
const handlers = {
[`set_main_${name}`]: mainHandlers.set_main,
};
return {
[name]: (state = {}, action)=>( get(handlers, action.type, d => d)(state, action))
}
}
// buildReducer('app_name')