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
/** | |
* match first character after white space | |
*/ | |
const firstAtWhiteSpace = /(^|\s)[a-z]/g; |
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
// in this case the state is each individual product | |
const product = (state, action) => { | |
switch (action.type) { | |
case 'CREATE_PRODUCT': | |
return { | |
id: action.id, | |
name: action.name, | |
price: action.price, | |
}; | |
case 'EDIT_PRODUCT': |
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
<!-- | |
even though the "blue" comes later in the list of classes, | |
but CSS rules of precedence actually depends of the order of | |
classes in the stylesheet | |
--> | |
<span class="red blue"> | |
so I'm red | |
</span> |
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
/** | |
* @link this is taken from here for reference | |
* https://github.com/testing-library/react-hooks-testing-library/issues/20#issuecomment-476628600 | |
*/ | |
import { useState, useEffect } from 'react'; | |
import { renderHook } from '@testing-library/react-hooks'; | |
describe('error hook tests', () => { | |
function useError(obj: Error | string): boolean { | |
if (obj.constructor.name === 'Error') { |
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
// .babelrc | |
{ | |
"presets": [ | |
[ | |
"@babel/preset-env", | |
{ | |
// this tells @babel "hey, don'y change any of the modules, let Webpack handle it | |
"modules": false | |
// you only get the individual pollyfill that you need | |
"useBuiltIns": "usage" |
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
interface Base { | |
id: string; | |
timestamp: string; | |
} | |
interface Product extends Base { | |
price: number; | |
stock: number; | |
} |
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
const { PerformanceObserver, performance } = require('perf_hooks'); | |
const obs = new PerformanceObserver((items) => { | |
console.log(items.getEntries()[0]); | |
performance.clearMarks(); | |
}); | |
obs.observe({ entryTypes: ['measure'] }); | |
const has = Object.prototype.hasOwnProperty; |
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
const connect = (mapStateToProps) => (Component) => { | |
return class Connect extends React.Component { | |
state = mapStateToProps(store.getState()); | |
componentDidMount() { | |
// когда store меняется, обновит компонент | |
this.unsubscribe = store.subscribe(this.update); | |
} | |
componentWillUnmount() { |
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
/** | |
* understanding .constructor property | |
*/ | |
function User() { | |
} | |
// when functions are created, they're given a "prototype" property which is an object | |
console.log(User.prototype); // {} |
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
const data = [ | |
{username: 'bob', age: 30, tags: ['work', 'boring']}, | |
{username: 'jim', age: 25, tags: ['home', 'fun']}, | |
{username: 'jane', age: 30, tags: ['vacation', 'fun']} | |
]; | |
R.filter(R.where({tags: R.contains('fun')}))(data); | |
const users = [ | |
{username: 'bob', age: 30, tags: [{label: 'work'}, {label: 'boring'}]}, |