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 target1 = document; // correct | |
const target2 = document.body; // correct | |
const target3 = document.getElementById('blockId'); // correct | |
const target4 = window; // wrong |
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
MutationRecord = { | |
addedNodes : [], // NodeList | |
attributeName : null, // attribute name - string or null | |
attributeNamespace : null, // attribute namespace | |
nextSibling : null, // next sibling in DOM | |
oldValue : null, // old value | |
previousSibling : null, // previous sibling in DOM | |
removedNodes : [], // NodeList of removed nodes | |
target : Element, // target element | |
type : "childList" // mutation type one of childList, attributes or characterData |
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
// target element that we will observe | |
const target = document.querySelector('div'); | |
// config object | |
const config = { | |
characterData: true, | |
characterDataOldValue: true, | |
childList: true, | |
subtree: true | |
}; |
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
// stop observing | |
observer.disconnect(); | |
// empties observer instance and returns records | |
observer.takeRecords(); // -> MutationRecords |
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 users = [ | |
{ 'user': 'barney', 'age': 36, 'active': true }, | |
{ 'user': 'fred', 'age': 40, 'active': false }, | |
{ 'user': 'pebbles', 'age': 1, 'active': true } | |
]; | |
const timerDateFindLodash = new Date(); | |
console.log('lodash find', find(users, ({ age }) => age < 40)); | |
console.log('lodash time', new Date() - timerDateFindLodash); |
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 numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | |
const timerDateReduceLodash = new Date(); | |
console.log('lodash reduce', reduce(numbers, (sum, n) => sum + n, 0)); | |
console.log('lodash time', new Date() - timerDateReduceLodash); | |
const timerDateReduceJS = new Date(); | |
console.log('native reduce', numbers.reduce((sum, n) => sum + n, 0)); | |
console.log('native time', new Date() - timerDateReduceJS); |
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
/** | |
* Main function | |
*/ | |
function find(collection, predicate, fromIndex) { | |
let iteratee | |
const iterable = Object(collection) | |
if (!isArrayLike(collection)) { | |
collection = keys(collection) | |
iteratee = (key) => predicate(iterable[key], key, iterable) |
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
reduce(map(filter(users, ({ active }) => active), ({ age }) => (age + 100) % 27), (p, c) => c > 20 ? p.concat(c) : p, []); |
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
users | |
.filter(({ active }) => active) | |
.map(({ age }) => (age + 100) % 27) | |
.reduce((p, c) => c > 20 ? p.concat(c) : p, []); |
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 React from 'react'; | |
class Swiper extends React.PureComponent { | |
startPointX = 0; | |
startPointY = 0; | |
direction = null; | |
clicked = false; | |
onMoveStart = ({ event, x, y }) => { | |
const { onMoveStart } = this.props; |