Skip to content

Commit

Permalink
prepare for using flags
Browse files Browse the repository at this point in the history
  • Loading branch information
maxfarseer committed Feb 16, 2020
1 parent c70d655 commit c10378e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/Main.elm
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
module Main exposing (main)

import Browser
import Html exposing (Html, div, h1, li, text, ul)



-- 🍏 🍐 🍌


type alias Fruit =
{ name : String
, emoji : String
}


type alias Flags =
{}

{-
обратите внимание как указан "банан"
Это просто еще один вариант создания "объекта".
Можно сказать, что type alias Fruit в какой-то мере
функция конструктор и придумать такой пример:
const banan = new Fruit('банан','смайлик')
Аргументы должны идти в таком же порядке,
в каком они перечислены в type alias
-}

type alias Model =
{}


fruits : List Fruit
Expand All @@ -37,8 +30,14 @@ fruits =
]


init : Flags -> ( Model, Cmd msg )
init flags =
( {}, Cmd.none )


-- функции для отрисовки
update : msg -> Model -> ( Model, Cmd msg )
update msg model =
( model, Cmd.none )


renderItem : Fruit -> Html msg
Expand All @@ -55,13 +54,20 @@ renderFruits data =
ul [] list



-- главная view функция


main =
view : Model -> Html msg
view model =
div []
[ h1 []
[ text "Сезон фруктов!" ]
, renderFruits fruits
]


main : Program Flags Model msg
main =
Browser.element
{ init = init
, view = view
, update = update
, subscriptions = \_ -> Sub.none
}
9 changes: 9 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { Elm } from './Main.elm'

const fruits = [
{ "name": "Яблоко", "emoji": "🍏" },
{ "name": "Груша", "emoji": "🍐" },
{ "name": "Банан", "emoji": "🍌" },
{ "name": "Апельсин", "emoji": "🍊" },
{ "name": "Лимон", "emoji": "🍋" }
]

Elm.Main.init({
flags: fruits,
node: document.querySelector('main')
})

0 comments on commit c10378e

Please sign in to comment.