A Pen by Barrett Sonntag on CodePen.
This file contains hidden or 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
| TLDR: __a_brief_description_of_the_issue_ | |
| Date: __the_date_and_time_that_the_bug_was_last_observed__ | |
| Environment/Link: __a_link_to_the_environment_with_the_selected_filters__ | |
| Screenshot/Video: | |
| __some_screengrab__ |
This file contains hidden or 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
| What: A_brief_description_of_what_is_involved_in_the_change | |
| Why: A_brief_description_as_to_why_this_change_is_needed | |
| How: Any_design_details_or_links | |
| Expected Outcome: |
This file contains hidden or 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
| type Position = [number,number] | |
| /** Return the angle between 2 points in radians relative to the x axis*/ | |
| export const points_to_radians = ([[p1lon, p1lat], [p2lon, p2lat]]: [ | |
| Position, | |
| Position, | |
| ]): number => Math.atan2(p2lat - p1lat, p2lon - p1lon); | |
| /** Return the angle between 2 points in degrees relative to the x axis */ |
This file contains hidden or 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 type { Reducer } from 'react'; | |
| import { useReducer, useState } from 'react'; | |
| const tempStateReducer = <T,>(prevState: T, newState: Partial<T>): T => ({ | |
| ...prevState, | |
| ...newState, | |
| }); | |
| /** | |
| * Hook to store temporary complex state until the user decides to accept or reject it |
This file contains hidden or 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
| /** | |
| * Container Queries | |
| * this utility provides container query functionality and | |
| * was copied from Phillip Walton's excellent blog post: | |
| * https://philipwalton.com/articles/responsive-components-a-solution-to-the-container-queries-problem/ | |
| */ | |
| (function (NAMESPACE, $) { | |
| "use strict"; |
This file contains hidden or 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
| // AND composition, apply all functions | |
| compose = fns => x => fns.reduceRight((y, f) => f(y), x); | |
| // OR composition, apply functions until one returns true | |
| composeAny = fns => x => fns.some(f => f(x)); |
This file contains hidden or 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
| //Single layer depth object comparison | |
| const shallowCompare = (obj1, obj2) => { | |
| return Object.keys(obj1).length === Object.keys(obj2).length && | |
| Object.keys(obj1).every(key => obj1[key] === obj2[key]); | |
| } | |
| //Distinct array | |
| const unique = (arr) => arr.reduce((acc, curr) => { | |
| if(!arr.some(val => shallowCompare(curr,val)){acc.push(curr)} | |
| return acc; |
This file contains hidden or 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 function useTraceUpdate(props) { | |
| const prev = useRef(props); | |
| useEffect(() => { | |
| const changedProps = Object.entries(props).reduce((ps, [k, v]) => { | |
| if (prev.current[k] !== v) { | |
| ps[k] = [prev.current[k], v]; | |
| } | |
| return ps; | |
| }, {}); | |
| if (Object.keys(changedProps).length > 0) { |
NewerOlder