Skip to content

Instantly share code, notes, and snippets.

@joanllenas
joanllenas / elm-misc-examples.md
Last active November 18, 2019 22:32
Elm examples
@joanllenas
joanllenas / controlled-input.elm
Created July 18, 2018 19:35
Controlled number input with Floats in Elm - the solution
module Main exposing (..)
import Html exposing (..)
import Html.Attributes as Attrs exposing (..)
import Html.Events exposing (..)
type Msg
= SetPrice String
@joanllenas
joanllenas / controlled-input.elm
Created July 18, 2018 18:37
Controlled number input with Floats in Elm - the problem
module Main exposing (..)
import Html exposing (..)
import Html.Attributes as Attrs exposing (..)
import Html.Events exposing (..)
type Msg
@joanllenas
joanllenas / app.component.html
Created February 12, 2018 00:14
RemoteData approach template - Slaying a UI Antipattern with Angular
<div class="pure-u-1-1 welcome" *ngIf="service.state | isNotAsked">
<p>Welcome, use the controls above to obtain today's sunset and sunrise times.</p>
</div>
<div class="pure-u-1-1" *ngIf="service.state | isLoading">
<p class="loading">
Loading...
</p>
</div>
@joanllenas
joanllenas / remote-data.ts
Created February 11, 2018 23:58
RemoteData approach - Slaying a UI Antipattern with Angular
export class NotAsked {}
export class Loading {}
export class Faliure<E> {
constructor(private error: E){}
fold(): E {
return this.error;
}
}
export class Success<T> {
constructor(private value: T){}
@joanllenas
joanllenas / app.component.html
Created February 11, 2018 23:46
Boolean approach template - Slaying a UI Antipattern with Angular
<div class="pure-u-1-1" *ngIf="service.state.isLoading">
<p class="loading">
Loading...
</p>
</div>
<div class="pure-u-1-1" *ngIf="!service.state.isLoading && !service.state.error && service.state.data">
<p>
Sunrise: {{ service.state.data.sunrise }}<br>
Sunset: {{ service.state.data.sunset }}
@joanllenas
joanllenas / sunriseSunset.service.ts
Created February 11, 2018 23:12
Boolean approach - Slaying a UI Antipattern with Angular
export interface SunriseState {
isLoading: boolean;
error: string;
data: {
sunrise: string,
sunset: string,
}
}
@joanllenas
joanllenas / MouseCoordinates.elm
Created January 7, 2018 16:06
Elm example: Capture div click mouse coordinates
-- https://ellie-app.com/fMXwpzt7va1/1
module MouseCoordinates exposing (..)
import Html exposing (Html, div, text, program)
import Html.Attributes exposing (style)
import Html.Events exposing (on)
import Json.Decode as Decode exposing (Decoder, map2, at, int)
-- MODEL
@joanllenas
joanllenas / tea2.elm
Last active January 4, 2018 11:39
Ejemplo del post "Otro sorbo de TEA"
module Counter exposing (..)
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (..)
programParams =
{ model = modelo
, view = vista