Skip to content

Instantly share code, notes, and snippets.

View revanth0212's full-sized avatar

Revanth Kumar Annavarapu revanth0212

View GitHub Profile
@revanth0212
revanth0212 / compose_implementation.js
Last active September 12, 2019 17:06
Custom implementation of Ramda's Compose Function without any dependencies. This function has been implemented with tail recursion, so no more stack overflow issues.
/**
* Compose function
*/
function _compose(functions, param) {
const lastFunction = functions.pop();
const result = lastFunction.call(null, param);
return functions.length === 0 ? result : _compose(functions, result);
}
@revanth0212
revanth0212 / LifeCycleMethodsUsingHooks.js
Last active August 31, 2019 16:59
A sample Hooks component demonstrating Life Cycle Methods Composition.
function useLikes() {
const [likes, setLikes] = useState(0)
const [likedByMySelf, setLikedByMySelf] = useState(false)
useEffect(() => {
fetchLikes().then(({ likes, likedByMySelf }) => {
setLikes(likes)
setLikedByMySelf(likedByMySelf)
})
}, [])
const onLike = () => {
[
{
"name":"country",
"path":[
"fields",
"country"
],
"props":{
"value":"USA"
}
@revanth0212
revanth0212 / HowToUseFieldCalculator.js
Created August 5, 2018 17:06
A sample to show how to use the field changes calculator.
const calculator = require('field-change-effects-calculator');
const changesCalculator = calculator(rules);
const calculateChanges = (event) => {
const state = getState()
const { name, value } = event.target
const changes = changesCalculator(state)(name, ['path', 'of', 'field', 'in', 'the', 'state', 'object'], value)
return changes
}
@revanth0212
revanth0212 / CountryAndPhoneNumberRules.js
Last active August 5, 2018 01:45
This is a sample rules object that shows the interaction between country and phone number fields in a state object.
const rules = {
country: [
{
name: 'phoneNumber',
path: ['fields', 'phoneNumber'],
props: (countryNewValue, state) => ({
editable: countryNewValue && countryNewValue !== '',
countryPhoneCode: countryPhoneCodeMapper[countryNewValue]
})
}
.OpsPortalCore {
width: 100%;
height: 100%;
padding-top: 50px;
}
.chargeInput input {
color: rgba(255, 255, 255, 1) !important;
text-align: center !important;
background-color: rgba(13, 93, 184, 1) !important;
/**
*** SIMPLE GRID
*** (C) ZACH COLE 2016
**/
@import url(https://fonts.googleapis.com/css?family=Lato:400,300,300italic,400italic,700,700italic);
/* UNIVERSAL */
html,
@revanth0212
revanth0212 / FindKthLargest-BST.js
Created June 24, 2018 22:35
Find the Kth largest element in a stream using a BST.
function Node(val) {
this.val = val
this.rightCount = 1
this.left = null
this.right = null
}
/**
* @param {number} k
* @param {number[]} nums