Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for use with turbo-rails #7

Open
ghost opened this issue Dec 12, 2022 · 0 comments
Open

Fix for use with turbo-rails #7

ghost opened this issue Dec 12, 2022 · 0 comments

Comments

@ghost
Copy link

ghost commented Dec 12, 2022

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"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants