Skip to content
This repository has been archived by the owner on Aug 4, 2023. It is now read-only.

Adonis package for working with Hotwire.js

Notifications You must be signed in to change notification settings

healthline/adonis-hotwire

 
 

Repository files navigation

Adonis Hotwire

Adonis v5 package for interacting with hotwire.

Installation

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.

node ace make:stimulus_controller <controller_name>

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.

Example:

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.

About

Adonis package for working with Hotwire.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 86.6%
  • JavaScript 11.3%
  • CSS 1.7%
  • Shell 0.4%