Skip to content

Instantly share code, notes, and snippets.

@danyx23
danyx23 / index.js
Created April 10, 2015 15:12
requirebin sketch
var h = require('virtual-dom/h');
var diff = require('virtual-dom/diff');
var patch = require('virtual-dom/patch');
var createElement = require('virtual-dom/create-element');
// 1: Create a function that declares what the DOM should look like
function render(value) {
return h('input', {
className: "form-control",
type: "range",
@danyx23
danyx23 / index.js
Created April 11, 2015 13:30
requirebin sketch
var h = require('virtual-dom/h');
var diff = require('virtual-dom/diff');
var patch = require('virtual-dom/patch');
var createElement = require('virtual-dom/create-element');
// 1: Create a function that declares what the DOM should look like
function render(value) {
return h('input', {
attributes: {
class: "form-control",
@danyx23
danyx23 / mediaAsset-model-draft.js
Last active August 29, 2015 14:20
Cycle model draft (not working) for more complex objects
// This doesn't work, it's just a draft while thinking how best to model collections of non-trivial objects
const model = (function () {
const mediaAsset$ = createStream(droppedFiles$.filter(droppedFile => droppedFile.type.match('image.*'))
.map (droppedfile => {
const reader = new FileReader();
const asset = {
id = cuid(),
name = droppedfile.name,
imageLoadSucceeded$ = Rx.Observable.fromEvent(reader.onload).map(_ => reader.result),
@danyx23
danyx23 / Main.elm
Last active January 16, 2016 13:06
Dealing with ports as part of the Elm Architecture
type PortAction
= StartAudioPlayback AudioPlaybackMessage
| StopAudioPlayback
| DecodeAudioData AudioRawDataMessage
| NoopPortAction
update : Action -> Model -> (Model, Effects Action, PortAction)
app : App Model MainActions.PortAction
app =
module CustomStartApp where
import Debug
import Html exposing (Html)
import Signal exposing (Address)
import Automaton exposing ((>>>))
type alias Config model action =
{ model : model
, view : Address action -> model -> Html
import Html exposing (div, button, text)
import Html.Events exposing (onClick)
import Signal exposing (Mailbox, mailbox, send)
import StartApp.Simple as StartApp
main =
StartApp.start { model = model, view = view, update = update }
model = "hi"
module PortsExample where
import Html exposing (div, button, text)
import Html.Events exposing (onClick)
import Signal exposing (Mailbox, mailbox, send)
import StartApp
import Effects
type alias Model = String
@danyx23
danyx23 / CustomStartApp.elm
Created February 24, 2016 20:48
Use ports with customized StartApp and "PortActions"
module CustomStartApp (start, App, Config) where
import Html exposing (Html)
import Effects exposing (Effects, Never)
import Task
type alias Config model action portAction =
{ init : ( model, Effects action, portAction )
, update : action -> model -> ( model, Effects action, Maybe portAction )
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
import System.Environment
import GHC.Generics
import Data.Aeson
import Data.Text (Text)
import Data.List (intersperse)
data MyMaybe a =
MyNothing
| MyJust a
deriving (Show)
instance Functor MyMaybe where
fmap _ MyNothing = MyNothing
fmap f (MyJust a) = MyJust (f a)