Skip to content

Instantly share code, notes, and snippets.

Avatar

Kyle Goggin kgoggin

View GitHub Profile
@kgoggin
kgoggin / ReducerWithEffects.re
Created May 18, 2021
Reducer With Side Effects
View ReducerWithEffects.re
module ReducerWithEffects = {
type actionWrapper('state, 'action) =
| Update('state)
| SideEffect(('action => unit) => unit)
| UpdateWithSideEffect('state, ('action => unit) => unit)
| NoUpdate;
type stateWrapper('state, 'action) = {
state: 'state,
effect: option(('action => unit) => unit),
@kgoggin
kgoggin / RecursiveGQLTypes.re
Created Apr 10, 2018
This gist shows how you could go about defining ReasonML types based on a GraphQL schema that reference each other, as well as a recursive decoder function used to parse a JSON response into the correct type.
View RecursiveGQLTypes.re
/* Use Reason's ability to define recursive types with the `and` keyword */
type movie = {
id: option(string),
name: option(string),
rating: option(Js.null(string)),
runTime: option(Js.null(int)),
actors: option(list(actor)),
}
and actor = {
id: option(string),
@kgoggin
kgoggin / ApolloCache.re
Last active Apr 27, 2020
Custom react-apollo ReasonML bindings
View ApolloCache.re
open ApolloTypes;
type js_read_query_options = {
.
"query": queryString,
"variables": Js.undefined(Js.Json.t),
};
type js_write_query_options = {
.
@kgoggin
kgoggin / README.md
Created Jun 11, 2019
Prisma Client Promise Weridness
View README.md

The prisma client has what it calls a "fluent" API, which allows you to chain requests for sub-types but work with them all as if they were a promise (docs). Example:

const organization = await prisma.schedule({id: "foo"{}).organization();

All of the examples in the documentation demonstrate using async/await syntax when working with the client. Inspecting what gets returned from a call to the client shows then and catch properties, like a normal promise, as well as the other fields exposed as functions (which is what allows the fluent API).

The Problem

View GraphQLTypes.re
let verifyGraphQLType = (~typeName, json) =>
switch (json->Js.Json.decodeObject) {
| None =>
Js.log({j|Unable to decode $typeName object|j});
raise(Not_found);
| Some(root) =>
switch (root->Js.Dict.get("__typeName")) {
| None =>
Js.log("Provided object is not a GraphQL object");
raise(Not_found);
View SketchSystems.spec
WelcomeScreen
newAccount -> ValidatePhoneNumber
signIn -> SignIn
searchForOrg -> SearchForOrg
SignIn
EnterPhone
usePW -> EnterUNPW
continue -> SendCode
back -> WelcomeScreen
SendCode
View StateChart.re
type stateDef('event, 'state) = {
on: 'event => option('state),
onEnter: option('event => unit),
onExit: option('event => unit),
};
module type Machine = {
/* type event; */
type state;
let initial: state;
View component.re
let getRouteComponent: ReasonReact.Router.url => ReasonReact.reactElement =
(url) =>
switch (MainRoutes.match(url)) {
| Home(_url) => <Page message="Home" />
| Admin(route) => <AdminRoot route />
| NotFound(_url) => <Page message="404" />
};
@kgoggin
kgoggin / CalSync
Last active Aug 29, 2015
One-way sync two calendars within OS X Calendar app. In this case, used to move events from an Exchange account to an iCloud account.
View CalSync
property today : current date
property bfCal : "*NAME OF SOURCE CALENDAR*"
property iCal : "*NAME OF DESTINATION CALENDAR*"
-- used for Growl notification
property allNotifications : {}
tell application "Calendar" to launch
tell application "Calendar" to reload calendars
-- wait for reload to happen