Skip to content

Instantly share code, notes, and snippets.

@Aesthetikx
Last active February 7, 2018 18:29
Show Gist options
  • Save Aesthetikx/e7b2438f9ed31e269489af9ef9235bc6 to your computer and use it in GitHub Desktop.
Save Aesthetikx/e7b2438f9ed31e269489af9ef9235bc6 to your computer and use it in GitHub Desktop.
Demonstration of embedded script tags influencing stimulus target detection
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="https://unpkg.com/stimulus/dist/stimulus.umd.js"></script>
<script>
(function() {
const application = Stimulus.Application.start()
const controller = class extends Stimulus.Controller {
connect() {
console.log('targets are one and two but not three', this.itemTargets);
}
};
Stimulus.Controller.targets = ['item'];
application.register("hello", controller);
})();
</script>
<head>
<body>
<div data-controller="hello">
<div data-target="hello.item">One</div>
<div data-target="hello.item">Two</div>
<script type="text/javascript">console.log('breaks');</script>
<div data-target="hello.item">Three</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment