Skip to content

Commit

Permalink
Merge pull request #900 from mendelk/document-local-turbolinks
Browse files Browse the repository at this point in the history
📝 Document integrating with Turbolinks when imported with Webpacker
  • Loading branch information
ttanimichi authored Jun 7, 2018
2 parents 467cbd8 + 018812c commit 83b6175
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,19 @@ ReactRailsUJS.detectEvents()

For example, if `Turbolinks` is loaded _after_ `ReactRailsUJS`, you'll need to call this again. This function removes previous handlers before adding new ones, so it's safe to call as often as needed.

If `Turbolinks` is `import`ed via Webpacker (and thus not available globally), `ReactRailsUJS` will be unable to locate it. To fix this, you can temporarily add it to the global namespace:

```js
// Order is particular. First start Turbolinks:
Turbolinks.start();
// Add Turbolinks to the global namespace:
window.Turbolinks = Turbolinks;
// Remove previous event handlers and add new ones:
ReactRailsUJS.detectEvents();
// (Optional) Clean up global namespace:
delete window.Turbolinks;
```

### `getConstructor`

Components are loaded with `ReactRailsUJS.getConstructor(className)`. This function has two built-in implementations:
Expand Down

0 comments on commit 83b6175

Please sign in to comment.