Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
StimulusReflex + SlimSelect that supports DOM mutations and reentrancy triggered by reflexes
<%= f.select :country_codes, country_select_data, {}, {multiple: true, data: {
controller: "select", action: "stimulus-reflex:after@document->select#delayedSetup", reflex: "change->Adapter#assign_attributes"}} %>
import ApplicationController from './application_controller'
import SlimSelect from 'slim-select'
export default class extends ApplicationController {
connect () {
this.setup()
}
disconnect (event) {
this.cleanup()
}
setup (event) {
this.cleanup()
this.slimSelect = new SlimSelect({
select: this.element
})
}
delayedSetup (event) {
setTimeout(this.setup.bind(this))
}
cleanup (event) {
if (!this.slimSelect) return
this.slimSelect.destroy()
delete this.slimSelect
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.