Skip to content

Instantly share code, notes, and snippets.

View drejohnson's full-sized avatar

DeAndre Johnson drejohnson

View GitHub Profile
@drejohnson
drejohnson / fela.re
Last active November 28, 2017 09:56
basic fela.js bindings for reasonml
type t;
[@bs.obj]
external renderer_options :
(
~plugins: array(t)=?,
~enhancers: array(t)=?,
~mediaQueryOrder: array(string)=?,
~supportQueryOrder: array(string)=?,
~selectorPrefix: string=?,
@drejohnson
drejohnson / styletron.re
Created November 28, 2017 06:10
basic styletron bindings for reasonml
type t;
type getStylesheetsHtmlMeth = {. "getStylesheetsHtml": [@bs.meth] (unit => unit)};
[@bs.val] external styletron_client_option : array(string) => t = "";
[@bs.module "styletron-client"] [@bs.new] external styletronClient : 'a => 'a = "default";
[@bs.module "styletron-server"] [@bs.new]
external styletronServer : unit => getStylesheetsHtmlMeth =
let unitConfig = Fela.Plugins.unit_config(~unit_="rem", ());
let extendPlugin = Fela.Plugins.extend;
let embeddedPlugin = Fela.Plugins.embedded;
let prefixerPlugin = Fela.Plugins.prefixer;
let fallbackValue = Fela.Plugins.fallbackValue;
module Moment = {
type t;
[@bs.send.pipe : t] external format : string => string = "";
[@bs.send.pipe : t] external utcOffset : string => t = "";
};
[@bs.module] external _moment : string => Moment.t = "moment";
let moment = (value) => _moment(value);
type selection = {
.
"alias": string,
"arguments": Js.Array.t(string),
"directives": Js.Array.t(string),
"kind": string,
"name": {
.
"kind": string,
"value": string
type hoc = ReasonReact.reactClass => ReasonReact.reactClass;
[@bs.module "react-apollo"] external graphql : GraphQLTag.definitions => hoc = "graphql";
module type Query = {type data; let query: GraphQLTag.definitions;};
module CreateWrapper = (Query: Query) => {
type props = {. "data": Query.data};
let wrapComponent = (~component, ~make) => {
let jsComponent =
@drejohnson
drejohnson / AWSAppSyncClient.re
Created May 17, 2018 22:17
Reason bindings for AWS AppSync
[@bs.module "aws-appsync"] [@bs.new]
external makeAWSAppSyncClient :
{
.
"url": Js.Nullable.t(string),
"region": Js.Nullable.t(string),
"auth":
Js.Nullable.t(
{
.
@drejohnson
drejohnson / fp-lenses.js
Created May 24, 2018 04:45 — forked from branneman/fp-lenses.js
JavaScript: Lenses (Functional Programming)
// FP Lenses
const lens = get => set => ({ get, set });
const view = lens => obj => lens.get(obj);
const set = lens => val => obj => lens.set(val)(obj);
const over = lens => fn => obj => set(lens)(fn(view(lens)(obj)))(obj);
const lensProp = key => lens(prop(key))(assoc(key));
@drejohnson
drejohnson / observer.js
Created July 1, 2018 11:06 — forked from ryanve/observer.js
Mutation observer example listening to any attribute changes
!function() {
var emitter = {
emit: console.dir.bind(console)
}
function emit(mutation) {
var target = mutation.target
var name = mutation.attributeName
var value = target.getAttribute(name)
@drejohnson
drejohnson / Main.elm
Created July 2, 2018 05:52 — forked from pablen/Main.elm
DOM mutation observer helper that will run a hook when a DOM node matching a selector is mounted or unmounted. This pattern is particularly useful for working with external JS libraries in your Elm apps, using minimal amount of code. The helper leverages the MutationObserver API (https://developer.mozilla.org/es/docs/Web/API/MutationObserver).
-- Somewhere in you Elm app you can add editor by adding an empty node with the correct attributes.
-- The JS library will be initialized and destroyed automatically!
view : Model -> Html Msg
view model =
div []
[ div
[ attribute "data-ace" ""
, attribute "data-ace-theme" "monokai"
, attribute "data-ace-mode" "javascript"