The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built...

36
2019/12/25 Gizra https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 1/36 The Safest Headless Drupal 8 with The Safest Headless Drupal 8 with Elm Elm Amitai Burtein // @amitaibu

Transcript of The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built...

Page 1: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 1/36

The Safest Headless Drupal 8 withThe Safest Headless Drupal 8 withElmElm

Amitai Burtein // @amitaibu

Page 2: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 2/36

Amitai Burstein@amitaibu

Spent a whole day in rural Rwanda, watching - in action - an @elmlang web-app with a #Drupal backend we've built for @ihanganeproject.

No marketing landing pages, no sale funnels, no targeted ads. Just a web-app that helps provide a better health care to mothers and their babies

158 12:20 AM - Nov 15, 2019

45 people are talking about this

Page 3: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 3/36

ElmElmGenerate JavaScript with great performance and no runtimeexceptions

Page 4: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 4/36

Page 5: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 5/36

module Counter exposing (..) import Html exposing (..) import Html.Attributes exposing (..) import Html.Events exposing (onClick) -- MODEL type alias Model = Int emptyModel : ModelemptyModel = 0 -- UPDATE type Msg = Decrement | Increment update : Msg -> Model -> ( Model, Cmd Msg ) update msg model =

case msg of

Page 6: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 6/36

Page 7: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 7/36

type alias Recipe = { title: String , image : String , preparationTime: Int }

Page 8: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 8/36

Types 101Types 101

Page 9: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 9/36

type Bool = False | True

Page 10: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 10/36

type DifficultyLevel = Easy | Normal | Hard type alias Recipe = { title: String , image : String , preparationTime: Int , difficultyLevel : DifficultyLevel }

Page 11: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 11/36

If something can go wrong, it willMurphy's law

type alias Recipe = { title: String , .. , isCarnivore : Bool , isVegetarian : Bool , isVegan : Bool } iAmConfused : RecipeiAmConfused = { title = "A vegan steak?!" , .. , isCarnivore = True , isVegetarian = False , isVegan = True }

Page 12: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 12/36

type DietaryRestriction = Carnivore | Vegetarian | Vegan type alias Recipe = { title: String , .. , dietaryRestriction : DietaryRestriction } thatIsBetter : RecipethatIsBetter = { title = "A vegan steak!" , .. , dietaryRestriction = Vegan }

Page 13: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 13/36

Page 14: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 14/36

type alias Recipe = { title: String , .. , preparationTime : Int , cookingTime : ? }

{ title: "foo" , preparationTime: 10, , cookingTime: null }

Page 15: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 15/36

!empty ?!empty ?

Page 16: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 16/36

type alias Recipe = { title: String , .. , preparationTime : Int , cookingTime : Maybe Int } iceCream : RecipeiceCream = { title = "Ice Cream" , .. , preparationTime = 10 , cookingTime = Nothing } pizza : Recipepizza = { title = "Pizza" , .. , preparationTime = 10 , cookingTime = Just 15 }

Page 17: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 17/36

type PreparationTimes = NoPreparation | Preparation Int (Maybe Int) type alias Recipe = { title: String , .. , preparationTimes : PreparationTimes } iceCreamFromRefrigerator : RecipeiceCreamFromRefrigerator = { title = "Ice Cream for lazy people" , .. , preparationTimes = NoPreparation } pizza : Recipepizza = { title = "Pizza" , .. , preparationTimes = Preparation 10 (Just 15) }

Page 18: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 18/36

type PreparationTimes = NoPreparation | Preparation Int (Maybe Int) viewPreparationTimes : Recipe -> Html msg viewPreparationTimes recipe = case recipe.preparationTimes of NoPreparation -> text "No preparation required" Preparation time Nothing -> text "Takes " ++ (String.fromInt time) ++ "minutes, but no cooking" Preparation time (Just cookingTime) -> text "Takes " ++ (String.fromInt time) ++ " minutes and " ++ (String.fromInt cookingTime " minutes for cooking"

Page 19: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 19/36

How to model the states of an HTTP request?

Page 20: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 20/36

type WebData a = NotAsked | Loading | Failure Http.Error | Success a type alias Recipe = { title: String , .. , preparationTimes : WebData PreparationTimes } viewPreparationTimes : Recipe -> Html msg viewPreparationTimes recipe = case recipe.preparationTimes of Failure error -> text "Error loading" Success preparationTimes -> case preparationTimes of NoPreparation -> text "No preparation required"

--

Page 21: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 21/36

Page 22: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 22/36

type alias Ingredient = { name: String , price : Int } type alias Recipe = { title: String , .. , ingredients : List Ingredient }

Page 23: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 23/36

map & fold

Page 24: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 24/36

viewIngredients : Recipe -> Html msg viewIngredients recipe = ul [] [ List.map ( \ingredient -> li [] [ text ingredient.name ] ) recipe.ingredients ] viewTotalPrice : Recipe -> Html msg viewTotalPrice recipe = List.foldl ( \ingredient accum -> accum + ingredient.price ) 0 recipe.ingredients

Page 25: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 25/36

Page 26: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 26/36

Page 27: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 27/36

Page 28: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 28/36

Page 29: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 29/36

Page 30: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 30/36

Page 31: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 31/36

Page 32: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 32/36

Page 33: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 33/36

Page 34: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 34/36

Page 35: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 35/36

Page 36: The Safest Headless Drupal 8 with - API-First CMS@elmlang web-app with a #Drupal backend we've built for @ihanganeproject . No marketing landing pages, no sale funnels, no targeted

2019/12/25 Gizra

https://gizra-presentations.github.io/drupalcamp-tokyo-2019/#/ 36/36