moduleParseModelwhereimportListexposing(filter,head)importMaybeexposing(withDefault)importStringexposing(dropLeft,split,startsWith,toInt)importHtmlexposing(..)importHtml.Attributesexposing(href,style)importHtml.Eventsexposing(onClick)importHttpexposing(url)-- MODELtypealiasModel=Int-- UPDATEtypeAction=Increment|Decrementupdate:Action->Model->Modelupdateactionmodel=caseactionofIncrement->model+1Decrement->model-1-- VIEWview:Signal.AddressAction->Model->Htmlviewaddressmodel=div[][button[onClickaddressDecrement][text"-"],statemodel,button[onClickaddressIncrement][text"+"]]-- INITIAL STATEquery2model:String->Stringquery2models=withDefault"?foo="(Justs)|>dropLeft1-- drop '?'|>split"&"|>filter(\term->startsWith"foo="term)|>head|>withDefault"foo=0"|>dropLeft4-- drop 'foo='parse:String->Intparses=casequery2models|>toIntofErrmsg->Debug.crashmsgOkval->val-- SAVE STATElinkToAppmodel=a["/assets/apps/elm/counterState/index.html?foo="++(toStringmodel)|>href][toStringmodel|>text]contentlink=div[ ][text"",link]statemodel=div[countStyle][linkToAppmodel|>content]-- CSScountStyle:AttributecountStyle=style[("font-size","20px"),("font-family","monospace"),("display","inline-block"),("width","50px"),("text-align","center")]
Build Snippet: build.bash
#!/bin/bash# ensure latest packages are downloaded
elm-package install--yes# only create the .js as we will rely on a custom html file (port)
elm-make Main.elm --output elm.js --yes# make elm js as small as possible
./.misc/jsmin/jsmin < elm.js > elm.min.js