Skip to content

Instantly share code, notes, and snippets.

View RyanCCollins's full-sized avatar

Ryan Collins RyanCCollins

View GitHub Profile
module UserMutations
// removed for brevity, see the rest
// here: https://github.com/RyanCCollins/meetup-event-planner/blob/master/app/graph/mutations/user_mutations.rb
UpdateProfile = GraphQL::Relay::Mutation.define do
name 'UpdateProfile'
description 'Update the user profile'
input_field :auth_token, !types.String
input_field :profile, ProfileInputType
return_field :user, AuthUserType
@RyanCCollins
RyanCCollins / actions.js
Created October 12, 2016 01:35
App Actions
export const authenticateUser = (user) => ({
type: types.AUTHENTICATE_USER,
user,
});
export const invalidateUser = () => ({
type: types.INVALIDATE_USER,
});
export const logoutUser = () => (dispatch) => {
// From https://github.com/RyanCCollins/ryancollinsio/blob/feat_rc_elm/client/webpack.config.babel.js
const webpack = require('webpack');
const path = require('path');
const ROOT_PATH = path.resolve(__dirname);
module.exports = {
devtool: 'eval',
entry: [
'react-hot-loader/patch',
import React, { Component } from 'react';
import Elm from 'react-elm-components';
import Heading from 'grommet-udacity/components/Heading';
import Section from 'grommet-udacity/components/Section';
import Markdown from 'grommet-udacity/components/Markdown';
import Box from 'grommet-udacity/components/Box';
import { StyledWrapper, StyledArticle } from './styles';
import { Main } from 'elm/src/Main';
import { Divider } from 'components';
// Main.elm
module Main exposing (main)
import AppModel exposing (..)
import View exposing (view)
import Html exposing (Html)
main : Program Never Model Msg
main =

Functional Programming in JS

Identity functor

const Identity = x => ({
  map: f => Identity(f(x)),
  fold: f => f(x),
  inspect: () => `Identity(${x})`
});
@RyanCCollins
RyanCCollins / reducer-example.js
Created January 5, 2017 03:47
Reducer example
export const initialState = {
error: null,
message: null,
isSubmitting: false,
modal: {
isVisible: false,
},
};
const feedbackReducer =
@RyanCCollins
RyanCCollins / model.elm
Created January 5, 2017 03:59
Elm reducer / union type example
type alias Model =
{ error: Maybe String
, message: Maybe String
, isSubmitting: Bool
}
type alias Error =
{ message: String }
type Msg
@RyanCCollins
RyanCCollins / typescript-union-types.ts
Last active January 5, 2017 05:36
TypeScript Union Types
type FeedbackAction = 'FEEDBACK_SUBMISSION_INITIATION' | 'FEEDBACK_SUBMISSION_MESSAGE' | 'FEEDBACK_SUBMISSION_ERROR'; // etc. etc.
interface IAction<P> {
type: FeedbackAction;
payload: P;
};
interface IFeedbackState {
error: Error;
message: string;
/* @flow */
type Maybe<T,U> = (pattern: {
some(x: T): U;
none(): U;
}) => U;
function map<A,B,C>(maybe: Maybe<A,C>, f: (a: A) => B): Maybe<B,C> {
return function(pattern) {
return maybe({