Skip to content

Instantly share code, notes, and snippets.

@davidkpiano
davidkpiano / reducer-with-effects.js
Last active Aug 20, 2021
An idea for actor-model-based effects with reducers
View reducer-with-effects.js
import {
useReducerWithEffects,
// hand-wavey, but meant to be used by React to create something
// external will produce async values sent to components
createEffect
} from 'react';
function fetchUserEffect(id, parentRef) {
const controller = new AbortController();
const signal = controller.signal;
@damianrr
damianrr / amplify-function-graphql-cognito.js
Last active Mar 6, 2020
How to query/mutate AppSync's GraphQL from within Amplify's lambda functions by login into Cognito user pool and reusing Authorization token.
View amplify-function-graphql-cognito.js
const R = require('ramda');
const aws = require("aws-sdk");
const { GraphQLClient } = require("graphql-request");
aws.config.update({
region: process.env.REGION
});
const cognitoidentityserviceprovider = new aws.CognitoIdentityServiceProvider({
apiVersion: "2016-04-18"
});
@undefobj
undefobj / index.js
Last active Jul 29, 2020
Calling AppSync from Lambda
View index.js
const https = require('https');
const AWS = require("aws-sdk");
const urlParse = require("url").URL;
const appsyncUrl = process.env.API_BACKENDGRAPHQL_GRAPHQLAPIENDPOINTOUTPUT;
const region = process.env.REGION;
const endpoint = new urlParse(appsyncUrl).hostname.toString();
const graphqlQuery = require('./query.js').mutation;
const apiKey = process.env.API_KEY;
exports.handler = async (event) => {
View Promise.re
let all = Js.Promise.all;
let resolve = Js.Promise.resolve;
let reject = Js.Promise.reject;
let andThen =
(p: Js.Promise.t('a), fn: 'a => Js.Promise.t('b)): Js.Promise.t('b) =>
p->Js.Promise.then_(fn, _);
@mhallin
mhallin / App.re
Created Aug 6, 2018
Async import pattern
View App.re
PageModule.fetchModule("./MyComponent")
|> Js.Promise.then_(m => send(SetRootElement(m())));
View match.js
const invalidMatchSignal = new Error();
function makeProxyThrower(input) {
return new Proxy(input, {
get(target, prop, receiver) {
if (prop in target) {
const result = Reflect.get(target, prop, receiver);
if (typeof result === "object" && result !== null) {
return makeProxyThrower(result);
@busypeoples
busypeoples / FormExample.re
Created Apr 23, 2018
Form Example in ReasonML
View FormExample.re
type validation('a) =
| NotEmpty
| Custom('a);
type t = string;
let validate = (rule, value, values) =>
switch (rule) {
| NotEmpty => String.length(value) > 0
| Custom(fn) => fn(value, values)
@Zerim
Zerim / SignupForm.re
Last active Feb 19, 2018
A simple SignupForm written in ReasonML
View SignupForm.re
/* `action` and `state` types must be defined before the `let component` statement for type inference to work */
type action =
| UpdateEmail string
| UpdatePassword string;
type state = {
email: string,
password: string
};
@lilactown
lilactown / promises.re
Last active Apr 24, 2020
Notes on using JavaScript Promises in ReasonML/BuckleScript
View promises.re
/**
* Making promises
*/
let okPromise = Js.Promise.make((~resolve, ~reject as _) => [@bs] resolve("ok"));
/* Simpler promise creation for static values */
Js.Promise.resolve("easy");
Js.Promise.reject(Invalid_argument("too easy"));
View postcss.config.js
module.exports = {
use: [
'autoprefixer',
'postcss-import',
'postcss-url',
'postcss-browser-reporter',
'postcss-reporter'
],
input: 'index.css',
output: 'dist/bundle.css',