This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {get, find} from lodash; | |
let object_data = { | |
"cat1": { | |
"video1": { | |
"active": true | |
} | |
} | |
} | |
let arrD = [{ | |
"cat": "cat1", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Authorized extends Component { | |
handleClick = () => { | |
const { onClick } = this.props | |
const authorized = checkAuthorization() | |
if (authorized) { | |
// console.log('authorixes') | |
onClick(d) | |
} | |
// show Not Authorize Popup | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function LayoutMain(WrappedComponent) { | |
class FormComponent extends Component { | |
renderControls() { | |
return <p>hi</p> | |
} | |
render() { | |
return ( | |
<WrappedComponent | |
{...this.props} | |
renderControls={this.renderControls} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import {useFormikContext} from 'formik' | |
import {pick} from 'lodash'; | |
export default (data)=>{ | |
return function FormVals(MainComponent) { | |
const FormComp = (props) => { | |
const mainProps = pick(useFormikContext(), data.pick || ['values']); | |
return <MainComponent {...{...props, ...mainProps}} /> | |
}; | |
return FormComp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as Validations from 'validation Module' | |
validationUpdate = ()=>{ | |
// select validation function by key | |
this.validations = map(this.props.validates, (d, key) => (get(Validations, key, false)(d))).filter(Boolean) | |
} | |
validation = (value) => { | |
// try to validate one by one | |
const valid = this.validations.reduce((res, fun) => (res || fun(value, {parentValues})), undefined) | |
return valid; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { Input } from 'antd' | |
class text extends Component { | |
change = (ev) => { | |
const { field} = this.props | |
field.onChange({ target: { name: field.name, value: ev.target.value } }); | |
// extra code after saving | |
} | |
render() { | |
const { field={}, placeholder, field_type='text'} = this.props |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * from './inputs' | |
class FormField extends Component { | |
shouldComponentUpdate(nextProps, nextState) { | |
// dependancy code for performance | |
} | |
render() { | |
const MainComponent = get(inputs, type, label); | |
return <> | |
<Label /> | |
<FieldComponent {...this.props}> |
OlderNewer