Last active
January 12, 2021 15:07
-
-
Save RolandStuder/7cc6851aaf83c42e8090415cbf7344f0 to your computer and use it in GitHub Desktop.
stimulus-reflex-lazy-loader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ApplicationController from './application_controller' | |
import StimulusReflex from "stimulus_reflex"; | |
export default class extends ApplicationController { | |
connect(){ | |
StimulusReflex.register(this) | |
if (!this.element.id) { | |
this.element.id = this.randomId() | |
} | |
this.loadReflex() | |
} | |
loadReflex(){ | |
if (this.isActionCableConnectionOpen()) { | |
this.stimulate(this.data.get('reflex'), this.element) | |
} else { | |
setTimeout(function () { | |
this.loadReflex() | |
}.bind(this), 10); | |
} | |
} | |
randomId() { | |
return Math.random().toString(32).replace(/[^a-z]+/g, '').substr(2, 10); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="div" data-controller="lazy-load" data-lazy-load-reflex="ExampleReflex#test"> | |
Placeholder | |
</div> |
It's been a while and I don't actually use this, but it used to work…
I don't have time right now to look into it. But I would recommend to use https://github.com/julianrubisch/futurism/ this is actually being worked on and will be more solid.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is it working? I get this error
stimulus_reflex.js:212 Uncaught The ActionCable channel subscription for StimulusReflex was rejected.