Skip to content

Instantly share code, notes, and snippets.

View maxfarseer's full-sized avatar

Max P maxfarseer

View GitHub Profile
@maxfarseer
maxfarseer / Base64ImgUrl.elm
Created April 26, 2020 14:40
Base64ImgUrl fixed
module Base64 exposing (Base64ImgUrl, decoderStringToBase64ImgUrl, fromString, toString)
import Json.Decode as JD
import String exposing (startsWith)
type Base64ImgUrl
= Base64ImgUrl String
@maxfarseer
maxfarseer / package.json
Created February 16, 2020 08:42
elm-webinar-2-setup-ide
{
"name": "elm-webinar-2",
"version": "1.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"clean": "rm dist/bundle.js",
"start": "parcel src/index.html",
"build-prod": "parcel build src/index.html"
},
@maxfarseer
maxfarseer / init-project-parcel.sh
Created February 16, 2020 08:01
Parcel init (elm #2)
npm install -g parcel-bundler
npm init -y
@maxfarseer
maxfarseer / reusable-ui-checkbox-example.elm
Created January 19, 2020 10:01
Narrowing-types_scaling_elm_apps
-- наш чекбокс (стандартный input type="checkbox")
checkbox : (Bool -> msg) -> Bool -> Html msg
checkbox toMsg isChecked =
input
[ type_ "checkbox"
, checked isChecked
, onCheck toMsg
]
[]
@maxfarseer
maxfarseer / narrow-types.elm
Created January 19, 2020 07:38
Narrowing-types_scaling_elm_apps
-- было
viewHeader : Model -> Html Msg
viewHeader model =
...127 lines
viewBody : Model -> Html Msg
viewBody model =
...349 lines
@maxfarseer
maxfarseer / newsModel.elm
Created November 19, 2019 13:30
data request initial model
type Model
= Не_запрашивали
| В_процессе
| Получено (Ошибка или Новости)
-- в переводе на англ
type Model
= NotAsked
| Loading
@maxfarseer
maxfarseer / reducer.js
Created November 19, 2019 13:25
data request initial state
initialState = {
data: [],
isLoading: false,
error: null,
}
<!-- ... -->
<script src="/elm.js"></script>
<script>
const errorLogger = error => console.error(`App Error: ${error}`);
const node = document.querySelector('#app');
// add flags here
const flags = {}
try {
const app = Elm.Main.init({ node, flags });
@maxfarseer
maxfarseer / custom-canvas.js
Last active November 17, 2019 18:25
Add custom web element & logic (Elm, Canvas, Fabric.js)
// пример custom web component
// который добавляет на страницу fabric.js (canvas) элемент
class CustomCanvas extends HTMLElement {
constructor() {
const self = super();
self._canvas = null;
self._ctx = null;
self._cf = null; // cf = canvas fabric instance
return self;
@maxfarseer
maxfarseer / custom.elm
Created November 17, 2019 18:23
Add custom web element & logic (Elm, Canvas, Fabric.js)
-- Main.elm -> добавляем "port"
port module Main exposing (main)
-- ...
-- добавляем команду
port sendDataToJs : String -> Cmd msg
-- update функция
case msg of