https://github.com/deriegle/adonis-hotwire
Adonis package for working with Hotwire.js
https://github.com/deriegle/adonis-hotwire
Last synced: about 2 months ago
JSON representation
Adonis package for working with Hotwire.js
- Host: GitHub
- URL: https://github.com/deriegle/adonis-hotwire
- Owner: deriegle
- Created: 2021-06-09T03:39:30.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-04-12T11:41:05.000Z (about 2 months ago)
- Last Synced: 2025-04-12T17:08:16.561Z (about 2 months ago)
- Language: TypeScript
- Size: 142 KB
- Stars: 3
- Watchers: 2
- Forks: 4
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# Adonis Hotwire
Adonis v5 package for interacting with [hotwire](https://turbo.hotwire.dev/).
## Installation
```bash
npm i adonis-hotwire @hotwired/turbo stimulus
node ace configure adonis-hotwire
```## Making a Stimulus Controller
There is an included command for generating new stimulus controllers. The new controller will be generating in the `resources/js/controllers/` folder.
```bash
node ace make:stimulus_controller
```## In your controller
You'll have access to an additional object in the `HttpContextContract` for interacting with turbo streams.
This object will provide methods for `append`, `prepend`, `replace`, `update` and `remove` actions.You can read more about their uses in the [Turbo Stream Handbook](https://turbo.hotwire.dev/handbook/streams).
Example:
```typescript
class MessagesController {
public async create({ request, turboStream }: HttpContextContract) {
const { content } = request.body()const message = await Message.create({
content,
})turboStream.append('messages', {
templatePath: 'messages/show',
locals: {
message,
},
})
}
}
```## Additional Documentation
Check out the `example/` directory in the Github repo for an example of using the `adonis-hotwire` package.