| Name of thing | Sorta like... | Mounted? | Can you even setState? | What would you say... ya do here? |
|---|---|---|---|---|
| constructor | initialize() | nope | nope | init stuff NO side effects |
| componentWillMount | beforeDomReady() | nope | yeah but don't | Only needed in createClass now use constructor for most things |
| render | render | nope | please no | render stuff and don't set any state please |
| componentDidMount | domReady() | yup | yup | DOM is a go init jQuery plugins dispatch stuff |
| componentWillReceiveProps | onChange() | yup | yup |
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
| #!/bin/bash | |
| # Function to extract sourceApiVersion from sfdx-project.json | |
| get_source_api_version() { | |
| local json_file="$1" | |
| local version=$(jq -r '.sourceApiVersion' "$json_file") | |
| echo "$version" | |
| } | |
| # Check if the correct number of arguments are provided |
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
| /** | |
| * Uses a JS Map structure to easily set & enforce unique keys. | |
| * Map Iterator is turned into an Array then ultimately reduced to | |
| * a single boolean for the Save button to disable against | |
| * | |
| * @param {Event} event | |
| */ | |
| formValidityCallback(event) { | |
| const { fieldId, isValid } = event.detail; |
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
| // https://www.w3.org/TR/html5/forms.html#valid-e-mail-address | |
| const remail = /^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/ |
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
| const copyToClipboard = str => { | |
| const el = document.createElement('textarea'); // Create a <textarea> element | |
| el.value = str; // Set its value to the string that you want copied | |
| el.setAttribute('readonly', ''); // Make it readonly to be tamper-proof | |
| el.style.position = 'absolute'; | |
| el.style.left = '-9999px'; // Move outside the screen to make it invisible | |
| document.body.appendChild(el); // Append the <textarea> element to the HTML document | |
| const selected = | |
| document.getSelection().rangeCount > 0 // Check if there is any content selected previously | |
| ? document.getSelection().getRangeAt(0) // Store selection if found |
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
| function responsivefy(svg) { | |
| // get container + svg aspect ratio | |
| var container = d3.select(svg.node().parentNode), | |
| width = parseInt(svg.style("width")), | |
| height = parseInt(svg.style("height")), | |
| aspect = width / height; | |
| // add viewBox and preserveAspectRatio properties, | |
| // and call resize so that svg resizes on inital page load | |
| svg.attr("viewBox", "0 0 " + width + " " + height) |
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
| // Filters duplicates from an array of Primitives (String, Bool, Num, null, undefined, Symbol) | |
| const returnedArray = array | |
| .map(obj => obj.name) | |
| .filter((elem, idx, arr) => arr.indexOf(elem) === idx); |
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
| // as if in a utils.js file | |
| const isObject = obj => { | |
| return Object.prototype.toString.call(obj) === '[object Object]' | |
| ? true | |
| : false; | |
| }; | |
| export const toArray = snap => { | |
| const array = []; |
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
| const _location = window.location | |
| const uAgent = window.navigator.userAgent.toLowercase() | |
| const query = <grab the query params according to your code base> | |
| if (uAgent.match(/iphone|ipod|ipad/i)) { | |
| handleIOS(location, query) | |
| } else if (uAgent.match(/android/i)) { | |
| handleAndroid(location, query) { | |
| } else { | |
| <User is on a desktop; I just logged a message to the console> |
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 React from 'react'; | |
| import injectStyle from './path/to/injectStyle'; | |
| export default class SampleComponent extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| const keyframesStyle = ` | |
| @-webkit-keyframes pulse { | |
| 0% { background-color: #fecd6d; } |
NewerOlder