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 const eventName = 'in view' | |
| export const tagName = 'inview-observer' | |
| const io = new IntersectionObserver((entries, observer) => { | |
| entries.forEach(entry => { | |
| const target = entry.target | |
| target.dispatchEvent(new Event('in view')) | |
| }) | |
| }, { threshold: 0.25 }) |
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 gFoo = function* () { | |
| const a = yield Promise.resolve(1) | |
| const b = yield Promise.resolve(2) | |
| const c = yield Promise.resolve(3) | |
| const d = yield Promise.resolve(4) | |
| return [a, b, c, d] | |
| } | |
| const co = genF => (...args) => { |
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 seenKeys = new Set() | |
| const MULTIPLIER = Math.pow(2, 24) | |
| const generateRandomKey = () => { | |
| const key = Math.floor(Math.random() * MULTIPLIER).toString(32) | |
| if (seenKeys.has(key) || !isNaN(+key)) | |
| return generateRandomKey() | |
| seenKeys.add(key) | |
| return key |
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 flatten1 = arr => { | |
| const result = [] | |
| for (const v of arr) { | |
| Array.isArray(v) ? | |
| result.push(...flatten(v)) : | |
| result.push(v) | |
| } | |
| return result |
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 cache = new WeakMap() | |
| export default async fileblob => new Promise((resolve, reject) => { | |
| if (cache.has(fileblob)) | |
| resolve(cache.get(fileblob)) | |
| const reader = new FileReader() | |
| reader.addEventListener('load', e => { | |
| const src = e.target.result | |
| cache.set(fileblob, src) |
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 cache = new WeakMap() | |
| export default src => new Promise((resolve, reject) => { | |
| if (cache.has(src)) | |
| resolve(cache.get(src)) | |
| const audio = document.createElement('audio') | |
| audio.addEventListener('loadedmetadata', e => { | |
| const duration = audio.duration | |
| cache.set(src, duration) |
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
| http://www.ics.uci.edu/~eppstein/161/960109.html |
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 cache = new Map() | |
| export default src => | |
| new Promise((resolve, reject) => { | |
| if (cache.has(src)) resolve(cache.get(src)) | |
| const audio = document.createElement('audio') | |
| audio.addEventListener('loadedmetadata', () => { | |
| const duration = audio.duration |
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 const sync = syncFn => (data, cb) => data |> syncFn |> cb; | |
| export const compose = (taskList, cb) => | |
| reduceRight((next, task) => data => task(data, next), cb, taskList); | |
| export const withErrorHandler = handler => | |
| map(task => (data, next) => | |
| data instanceof Error ? handler(data) : task(data, next) | |
| ); |
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 styled, { keyframes } from 'styled-components' | |
| const Svg = styled.svg.attrs({ | |
| version: '1.1', | |
| xmlns: 'http://www.w3.org/2000/svg', | |
| xmlnsXlink: 'http://www.w3.org/1999/xlink', | |
| 'xmlns:sketch': 'http://www.bohemiancoding.com/sketch/ns' | |
| })` | |
| position: relative; |