Skip to content

Instantly share code, notes, and snippets.

☕️
j chillin

Chris Opperwall copperwall

☕️
j chillin
Block or report user

Report or block copperwall

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View generator_1.js
function *sortOfAsyncFunction() {
const ivysaur = yield fetch('https://pokeapi.co/api/v2/pokemon/ivysaur');
return pikachu.name.toUpperCase();
}
// "IVYSAUR"
runner(sortOfAsyncFunction).then(result => console.log(result));
View runner.js
function runner(gen, ...args) {
// Initialize the generator.
let iterator = gen(...args);
// handleNext is responsible for restarting the generator with new input.
return Promise.resolve().then(function handleNext(value) {
// next can be a promise or a sync value.
let next = iterator.next(value);
// handleResult is responsible for taking the output of the generator
View async_2.js
async function doStuff() {
const partyProfileRes = fetch('/v1/users');
const accountRes = fetch('/v1/customers');
const [partyProfile, account] = await Promise.all([
partyProfileRes,
accountRes
]);
try {
View promise_1.js
function getGuides() {
let ids = [...Array(10).keys()];
return ids.reduce((accumulator, id) => {
return accumulator.then(results => {
return fetch(id).then(result => {
results.push(result);
return results;
});
});
View form_submit.js
Form.onSubmitFactory = fn => form => ev => {
ev.preventDefault();
fn(Form.getData(form));
};
View form_onchange.js
Form.onChangeFactory = fn => (form, fieldKey) => updatedProps => fn({
...form,
fields: {
...form.fields,
[fieldKey]: {
...form.fields[fieldKey],
...updatedProps,
},
},
});
View form_props.js
Form.getProps = form => Object.assign({},
...Object.entries(form)
.filter(([formPropKey, formProp]) => formPropKey !== 'fields')
.map(([formPropKey, formProp]) => ({
[formPropKey]: formProp instanceof Function ? formProp(form) : formProp,
})),
{
fields: Object.assign({}, ...Object.entries(form.fields).map(([fieldKey, field]) => ({
[fieldKey]: Object.assign({}, ...Object.entries(field).map(([fieldPropKey, fieldProp]) => ({
[fieldPropKey]: fieldProp instanceof Function ? fieldProp(form, fieldKey) : fieldProp,
View form_data.js
Form.getData = form => Object.assign({},
...Object.entries(Form.getProps(form).fields)
.filter(([fieldKey, field]) => !field.disabled)
.filter(([fieldKey, field]) =>
!['checkbox', 'radio'].includes(field.type) || field.checked
)
.map(([fieldKey, field]) => ({ [fieldKey]: field.value })),
);
View form_fields.js
Form.fields = (globalProps = {}, fields) => Object.assign({},
...Object.entries(fields).map(([fieldKey, field]) => ({
[fieldKey]: {
...Form.Field.defaultProps,
...{ name: fieldKey },
...globalProps,
...field,
},
})),
);
View form_fields.js
Form.fields = (globalProps = {}, fields) => Object.assign({},
...Object.entries(fields).map(([fieldKey, field]) => ({
[fieldKey]: {
...Form.Field.defaultProps,
...{ name: fieldKey },
...globalProps,
...field,
},
})),
);
You can’t perform that action at this time.