Created
August 13, 2020 14:35
-
-
Save hopsoft/13f10225c7cdc6d08a5150f192466a40 to your computer and use it in GitHub Desktop.
StimulusReflex + SlimSelect that supports DOM mutations and reentrancy triggered by reflexes
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
<%= f.select :country_codes, country_select_data, {}, {multiple: true, data: { | |
controller: "select", action: "stimulus-reflex:after@document->select#delayedSetup", reflex: "change->Adapter#assign_attributes"}} %> |
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 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