An unofficial Cookbook for PureScript
The recipes folder contains all the recipes in this repo in no particular order.
If you want to contribute a new recipe, see the CONTRIBUTING.md file.
Install GNU Make (version 4.0 or above), and verify installation with:
make --version
Install all dependencies locally:
make installDeps
Install for Nix users:
# Remove purescript and spago and removing traling , from package.json
sed --in-place '/purescript\|spago/d' ./package.json && sed --in-place '$!N;s/,\n }/\n }/;P;D' package.json
nix-shell
See a list of available recipe launch commands by running make list
:
> make list
Use "make RecipeName-target" to run a recipe
=== Node Recipes ===
make ReadPrintFileContents-node
make HelloLog-node
...
=== Web Recipes ===
make WindowProperties-web
make HelloLog-web
...
Then simply copy and paste one of the listed commands. For example:
Running a node-compatible recipe:
> make HelloLog-node
=== Running HelloLog on the Node.js backend ===
[info] Installation complete.
[info] Build succeeded.
Hello world!
Running a web-compatible recipe:
> make HelloLog-web
=== Building HelloLog ===
[info] Installation complete.
[info] Build succeeded.
=== Launching HelloLog in the web browser ===
...
Recipes ending with ... | ... mean the following approach/library is used |
---|---|
HalogenClassic |
Component-style Halogen |
HalogenHooks |
Hooks-style Halogen |
ReactClassic |
Component-style React via react-basic |
ReactHooks |
Hooks-style React via react-basic |
Concur |
Concur |
Js |
Run plain PureScript only on the web (no node.js) without a web framework |
Log |
Log content to both the browser's dev console and the terminal |
Node |
Run PureScript only on Node.js where no user interaction occurs |
CLI |
Run PureScript only on Node.js with user interaction |
Node | Web Browser | Recipe | Description |
---|---|---|---|
✔️ | AceEditorHalogenHooks | A Halogen Hooks port of the "Ace Editor" Halogen Example. | |
✔️ | AddRemoveEventListenerJs | This recipe shows how to add and remove an event listener to an HTML element. | |
✔️ | BasicHalogenHooks | Displays a button that toggles the label to "On" and "Off". | |
✔️ | ✔️ | BigIntJs | This recipe shows how to print, create, and use values of the BigIntJs type in either the node.js or web browser console. |
✔️ | BookHalogenHooks | A Halogen port of the "HTTP - Book" Elm Example. | |
✔️ | BookReactHooks | A React port of the "HTTP - Book" Elm Example. | |
✔️ | ButtonsHalogenHooks | A Halogen port of the "User Input - Buttons" Elm Example. | |
✔️ | ButtonsReactHooks | A React port of the "User Input - Buttons" Elm Example. | |
✔️ | CardsHalogenHooks | A Halogen port of the "Random - Cards" Elm Example. | |
✔️ | CardsReactHooks | A React port of the "Random - Cards" Elm Example. | |
✔️ | CatGifsHalogenHooks | A Halogen port of the "HTTP - Cat GIFs" Elm Example. | |
✔️ | ComponentsHalogenHooks | Demonstrates how to nest one Halogen-Hooks-based component inside another and send/receive queries between the two. | |
✔️ | ComponentsInputHalogenHooks | Each time a parent re-renders, it will pass a new input value into the child, and the child will update accordingly. | |
✔️ | ComponentsMultiTypeHalogenHooks | Demonstrates a component that can communicate with its children that have differing types. | |
✔️ | ✔️ | DebuggingLog | This recipe shows how to do print-debugging using the Debug module's spy and traceM functions. The compiler will emit warnings to remind you to remove these debug functions before you ship production code. |
✔️ | DiceCLI | This recipe shows how to create an interactive command line prompt that repeatedly generates a random number between 1 and 6. | |
✔️ | ✔️ | DiceLog | This recipe shows how to log a random integer between 1 and 6 (representing a roll of a die) in either the node.js or web browser console. |
✔️ | DragAndDropHalogenHooks | A Halogen port of the "Files - Drag-and-Drop" Elm Example. | |
✔️ | DriverIoHalogenHooks | Demonstrates how to communicate with a Halogen application by sending messages to and receiving messages from the root-level component via the driver. | |
✔️ | DriverRoutingHalogenHooks | Demonstrates using hashchange events to drive the root component in a Halogen application via the driver. |
|
✔️ | DriverWebSocketsHalogenHooks | Demonstrates using a WebSocket to drive the main component in a Halogen application. | |
✔️ | FileUploadHalogenHooks | A Halogen port of the "Files - Upload" Elm Example. | |
✔️ | FindDomElementJs | This recipe shows how to find elements in the DOM by using query selectors. | |
✔️ | FormsReactHooks | A React port of the "User Interface - Forms" Elm Example. | |
✔️ | GroceriesHalogenHooks | A Halogen port of the "HTML - Groceries" Elm Example. | |
✔️ | GroceriesReactHooks | A React port of the "HTML - Groceries" Elm Example. | |
✔️ | HelloConcur | A Concur port of the "HTML - Hello" Elm Example. | |
✔️ | HelloHalogenHooks | A Halogen port of the "HTML - Hello" Elm Example. | |
✔️ | ✔️ | HelloLog | This recipe shows how to run a simple "Hello world!" program in either the node.js or web browser console. |
✔️ | HelloReactHooks | A React port of the "HTML - Hello" Elm Example. | |
✔️ | ✔️ | HeterogenousArrayLog | This recipe demonstrates how to create a heterogenous array and process its elements. |
✔️ | ImagePreviewsHalogenHooks | A Halogen port of the "Files - Drag-and-Drop" Elm Example. | |
✔️ | InterpretHalogenHooks | Demonstrates how to use a custom monad (in this case, using ReaderT with Aff as the effect type) for a component, and then interpreting that custom monad back down to Aff , so it can be run as a normal component. |
|
✔️ | KeyboardInputHalogenHooks | This example demonstrates how to selectively capture keyboard events and, more generally, how to use EventSource s in Halogen. |
|
✔️ | LifecycleHalogenHooks | Demonstrates component lifecycle. | |
✔️ | NumbersHalogenHooks | A Halogen port of the "Random - Numbers" Elm Example. | |
✔️ | NumbersReactHooks | A React port of the "Random - Numbers" Elm Example. | |
✔️ | PositionsHalogenHooks | A Halogen port of the "Random - Positions" Elm Example. | |
✔️ | PositionsReactHooks | A React port of the "Random - Positions" Elm Example. | |
✔️ | ReadPrintFileContentsNode | Reads a file's contents and prints it to the console. | |
✔️ | RoutingHashHalogenClassic | This recipe shows how to use purescript-routing to do client-side hash-based routing in a Halogen-based single-page application (SPA). |
|
✔️ | RoutingHashLog | This recipe demonstrates hash-based routing with purescript-routing . No web framework is used. |
|
✔️ | RoutingPushHalogenClassic | This recipe shows how to use purescript-routing to do client-side push-state routing in a Halogen-based single-page application (SPA). |
|
✔️ | TextFieldsHalogenHooks | A Halogen port of the "User Interface - Text Fields" Elm Example. | |
✔️ | TextFieldsReactHooks | A React port of the "User Interface - Text Fields" Elm Example. | |
✔️ | TimeHalogenHooks | A Halogen port of the "Time - Time" Elm Example. | |
✔️ | TimeReactHooks | A React port of the "User Interface - Time" Elm Example. | |
✔️ | WindowPropertiesJs | This recipe shows how to get and print various properties in the browser's window object. |
|
✔️ | WriteFileNode | Writes a String to a text file using UTF-8 encoding. |