Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pta2002/gleam-radiate
Hot code reloading for Gleam
https://github.com/pta2002/gleam-radiate
gleam
Last synced: 27 days ago
JSON representation
Hot code reloading for Gleam
- Host: GitHub
- URL: https://github.com/pta2002/gleam-radiate
- Owner: pta2002
- License: apache-2.0
- Created: 2023-10-21T17:10:26.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-27T08:00:32.000Z (4 months ago)
- Last Synced: 2024-09-16T17:53:44.802Z (about 2 months ago)
- Topics: gleam
- Language: Gleam
- Homepage:
- Size: 24.4 KB
- Stars: 27
- Watchers: 3
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# radiate
[![Package Version](https://img.shields.io/hexpm/v/radiate)](https://hex.pm/packages/radiate)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/radiate/)Hot reloading while in development for Gleam!
## Introduction
Radiate will watch any directory you specify for changes. When a file is
changed in that directory, it'll check if it's a Gleam file, and if it is, the
project will be recompiled and all modified modules will be reloaded, without
having to restart the BEAM VM.## Quick start
```gleam
// On main.gleam
import gleam/erlang/process
import gleam/io
import radiate
import messagepub fn main() {
let _ =
radiate.new()
|> radiate.add_dir("src")
|> radiate.start()let timer_subject = process.new_subject()
print_every_second(timer_subject)
}fn print_every_second(subject: process.Subject(Nil)) {
process.send_after(subject, 1000, Nil)let _ = process.receive(subject, 1500)
io.println(message.get_message())print_every_second(subject)
}// On message.gleam
pub fn get_message() -> String {
"Hello!"
}
```When you first run this, it'll print "Hello!" every second.
Now, go ahead and change the text `get_message` returns to `"Hello, world!"`, and save the file.
As soon as you save, the message printed is changed to "Hello, world!", without needing to restart the program!
### Warning for macOS users
Right now, the `add_dir` function only supports `"."` or an absolute path! Be careful to resolve the path to get it work if you want to watch `"src"` for example.
## Adding a callback
You can add callbacks to be run every time code is reloaded through `on_reload`:
```gleam
import radiate
import gleam/iopub fn main() {
let _ = radiate.new()
|> radiate.add_dir("src")
|> radiate.on_reload(fn (_state, path) {
io.println("Change in " <> path <> ", reloading!")
})
|> radiate.start()
}
```## Installation
This package can be added to your Gleam project:
```sh
gleam add radiate
```and its documentation can be found at .