Created
July 24, 2016 18:58
-
-
Save dtothefp/31f05d852c1e71c11df259967a5b5179 to your computer and use it in GitHub Desktop.
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 run(gen) { | |
// const it = gen() | |
// return new Promise((res, rej) => { | |
// function next(err, data) { | |
// let nextData; | |
// if (err !== undefined && err !== null) { | |
// nextData = it.throw(err) | |
// } else { | |
// nextData = it.next(data) | |
// } | |
// const {value, done} = nextData; | |
// if (done) { | |
// res(value) | |
// } else { | |
// const fn = value | |
// fn(next) | |
// } | |
// } | |
// next() | |
// }) | |
// } | |
// function thunk(fn, opts = {}) { | |
// const {ctx = fn} = opts | |
// return (...args) => { | |
// return (cb) => { | |
// fn.apply(fn, [...args, cb]) | |
// } | |
// } | |
// } | |
// function readAsync(fp, cb) { | |
// setTimeout(() => { | |
// if (succeeds()) { | |
// return cb(null, {success: true, fp}) | |
// } | |
// cb(new Error(`big error${fp}`)) | |
// }, 1000) | |
// } | |
// function succeeds() { | |
// return Math.random() > 0.5 | |
// } | |
// const read = thunk(readAsync); | |
// const end = run(function *() { | |
// const read1 = read('first/fp') | |
// const read2 = read('second/fp') | |
// try { | |
// const data = yield read1 | |
// console.log('first data: ', data) | |
// } catch (err) { | |
// console.log('first err: ', err.message) | |
// } | |
// try { | |
// const data = yield read2 | |
// console.log('second data: ', data) | |
// } catch (err) { | |
// console.log('second err: ', err.message) | |
// } | |
// return 'all done :-)' | |
// }) | |
// end.then((data) => { | |
// console.log('end', data) | |
// }).catch((err) => { | |
// console.log('prom err', err) | |
// }) | |
function *errorCatcher(arr) { | |
for (const item of arr) { | |
try { | |
yield item | |
} catch (err) { | |
console.log('err: ', err.message, 'item: ', item) | |
} | |
} | |
} | |
const data = [1, 2, 3] | |
const gen = errorCatcher(data) | |
let nextData; | |
nextData = gen.next() | |
console.log(nextData) //{"value":1,"done":false} | |
nextData = gen.throw(new Error('uh oh')) | |
// log from caught error err: uh oh item: 1 | |
console.log(nextData) //{"value":2,"done":false} | |
nextData = gen.next() | |
console.log(nextData) //{"value":3,"done":false} | |
nextData = gen.next() | |
console.log(nextData) //{"done":true} | |
const reactAcceptedAttributes = ` | |
accept acceptCharset accessKey action allowFullScreen allowTransparency alt | |
async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge | |
charSet checked cite classID className colSpan cols content contentEditable | |
contextMenu controls coords crossOrigin data dateTime default defer dir | |
disabled download draggable encType form formAction formEncType formMethod | |
formNoValidate formTarget frameBorder headers height hidden high href hrefLang | |
htmlFor httpEquiv icon id inputMode integrity is keyParams keyType kind label | |
lang list loop low manifest marginHeight marginWidth max maxLength media | |
mediaGroup method min minLength multiple muted name noValidate nonce open | |
optimum pattern placeholder poster preload profile radioGroup readOnly rel | |
required reversed role rowSpan rows sandbox scope scoped scrolling seamless | |
selected shape size sizes span spellCheck src srcDoc srcLang srcSet start step | |
style summary tabIndex target title type useMap value width wmode wrap | |
`; | |
console.log(reactAcceptedAttributes.split(' ').map(attr => attr.replace(/\r?\n|\r/, '')).filter(attr => !!attr)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment