This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
repos=("rippinrobr/csv-to.git" "rippinrobr/retrosheet-rs" "rippinrobr/gh-tools" | |
"rippinrobr/cli-book-apps" "rippinrobr/barrel" "rippinrobr/baseball-stats-db" "rippinrobr/hockey-databank") | |
src_base_dir="../src" | |
github_base_uri="[email protected]:" | |
cd $src_base_dir |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// click_examples_init is called from the init() function in src/lib.rs | |
// it is responsible for registering a click event handler. If there is no | |
// element found with the given id, then an alert button is displayed with | |
// an error message | |
pub fn click_examples_init(elem_id: String, txt_id: String) { | |
match super::get_element_by_id(&elem_id) { | |
Some(btn) => register_click_handler(btn.as_ref() as &web_sys::EventTarget, txt_id), | |
None => super::alert(&format!("No element was found with the id {}", elem_id)), | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// js_click_event_handler is called by the js code in a more | |
// 'tradiitional event listerner approach. It will popup an | |
// alert dialog and display the click event information | |
#[wasm_bindgen] | |
pub fn js_click_event_handler(evt: web_sys::MouseEvent) { | |
super::alert(&format!("[js handler]\n{:#?}", Click::new(evt))); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as wasm from "wasmcookbook"; | |
// setup the listener to call the rust function | |
document.getElementById("btn-js-click").addEventListener('click', wasm.js_click_event_handler); | |
// This struct that is being created is used | |
// to pass the ids of the HTML elements that | |
// the code interacts with. I want to avoid | |
// hard-coding the ids in the rust code, so I | |
// decided to do it in JS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type alias Conspiracy = { | |
title : String | |
,page_id : String | |
,summary : String | |
,content : String | |
,background: String | |
} | |
-- conspiracyDecoder is the code that pulls the data out of the JSON object |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- getConspiracies is responsible for making the HTTP GET | |
-- call to fetch the conspiracies for a given category. The |> is a pipe operator and I'm | |
-- using to create a 'pipeline'. The Json.Decode.list conspiracyDecoder is passed to | |
-- the Http.get call as the last parameter and is responsible for turning the JSON | |
-- Array of Category object into an Elm list of Conspiracies. The List of conspiracies | |
-- from the decoder become the parameter of the DataRecieved Msg and | |
-- eventually become the content on the right of the page | |
getConspiracies : Int -> Cmd Msg | |
getConspiracies category_id = | |
Json.Decode.list conspiracyDecoder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- update drives the changes in the UI and interaction with the server. | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
DataReceived (Ok categories) -> | |
({ model | categories = categories, errorMsg = Nothing }, Cmd.none) | |
DataReceived (Err httpError) -> | |
({ model | errorMsg = Just (createErrorMessage httpError) }, Cmd.none) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- getCategoriesCommand is responsible for making the HTTP GET | |
-- call to fetch the tags. |> is a pipe operator and I'm using to create a 'pipeline'. | |
-- The Json.Decode.list tagDecoder is passed to the Http.get call as the last parameter | |
-- and is responsible for turning the JSON Array of categories into an Elm list of Categories. | |
-- The List of Categories from the decoder become the parameter of the DataRecieved Msg and | |
-- eventually become the navigation list | |
getCategoriesCommand : Cmd Msg | |
getCategoriesCommand = | |
Json.Decode.list categoryDecoder | |
|> Http.get "http://localhost:8088/categories" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type alias Category = { | |
id : Int | |
,name : String | |
,approved : Int | |
} | |
-- categoryDecoder is the code that pulls the data out of the JSON object | |
-- and creates a Category object | |
categoryDecoder : Decoder Category | |
categoryDecoder = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{"id":5, | |
"name":"9/11", | |
"approved":1}, | |
{"id":9,"name":"Assassinations","approved":1}, | |
{"id":10,"name":"CIA/FBI/NSA","approved":1}, | |
{"id":8,"name":"Conspiracy Studies","approved":1}, | |
{"id":7,"name":"End of the World","approved":1}, | |
{"id":13,"name":"Paranormal","approved":1}, | |
{"id":12,"name":"Political","approved":1}, |
NewerOlder