Skip to content

Instantly share code, notes, and snippets.

Namespace your flux action types to prevent collisions:

function constants(namespace, constants) {
  return Object.freeze(
    constants.reduce((obj, constant) => {
      return {
        ...obj,
        [constant]: `${namespace}/${constant}`
 }

Animations:

  • shouldComponentUpdate
  • <StaticContainer>
  • Element caching
  • Raw DOM mutations
  • data binding

Falcor:

{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Control.Monad.Except (ExceptT)
import qualified Control.Monad.Except as Except
import Control.Monad.Free
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Control.Monad.Free
import Control.Monad.Free.TH
import Control.Monad.State
@jhewlett
jhewlett / nested-match.fs
Last active January 3, 2019 14:30
Nested match
let findThing id =
match findThingA id with
| None -> None
| Some thingA ->
match findThingB id with
| None -> None
| Some thingB ->
combine thingA thingB
@jhewlett
jhewlett / nested-bind.fs
Last active December 18, 2018 19:53
Nested bind
let findThing id =
findThingA id
|> Option.bind (fun thingA ->
findThingB id
|> Option.bind (fun thingB ->
combine thingA thingB))
@jhewlett
jhewlett / remove-nesting.fs
Last active December 18, 2018 19:53
Remove nesting through CEs
maybe {
let! thingA = findThingA id
let! thingB = findThingB id
return combine thingA thingB
}
@jhewlett
jhewlett / nested-checks.fs
Last active December 18, 2018 19:42
Nested authorization checks
match firstCheck () with
| Some c when c.CanRead -> Ok ()
| _ ->
match secondCheck () with
| Some c when c.CanRead -> Ok ()
| _ ->
match thirdCheck () with
| Some c when c.CanRead -> Ok ()
| _ -> Error NotAuthorized
@jhewlett
jhewlett / independent-authz-checks.fs
Last active December 18, 2018 19:47
Independent authorization checks
let firstCheckResult () : Result<unit, NotAuthorized> =
match firstCheck () with
| Some c when c.CanRead -> Ok ()
| _ -> Error NotAuthorized
let secondCheckResult () : Result<unit, NotAuthorized> =
match secondCheck () with
| Some c when c.CanRead -> Ok ()
| _ -> Error NotAuthorized
@jhewlett
jhewlett / sequence-checks.fs
Last active December 18, 2018 19:44
Sequence of checks
let allResults : Result<unit, NotAuthorized> seq =
seq {
yield firstCheckResult ()
yield secondCheckResult ()
yield thirdCheckResult ()
}