Skip to content

Fix for use with turbo-rails #7

@ghost

Description

Came up with a simple file to use @hotwired/turbo-rails so @hotwired/turbo doesn't need imported when using rails. Tested using local turbo-morph.js file with import maps and works great. Took out all initializers and exports as I found they weren't needed. Got a good way to implement in the lib? Also should give ideas to help turbo_power-rails.

turbo-morph.js

import morphdom from "morphdom"
import { Turbo } from "@hotwired/turbo-rails"

Turbo.StreamActions.morph = function() {
  const options = {
    childrenOnly: this.hasAttribute("children-only")
  }

  this.targetElements.forEach(element => {
    morphdom(element, options.childrenOnly ? this.templateContent : this.templateElement.innerHTML, options)
  })
}

application.js

import "@hotwired/turbo-rails"
import "turbo-morph"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions