I've been thinking about this quite a bit. My only hesitation is trying to find a usage that would be globally beneficial to the community. Ideally, I would want to avoid anything related to cryptocurrencies in the episode and focus on the actual technology. Are there any use cases that you can think of that would be good to cover?
Some great ideas. I'll look into some of these.
Thanks vad2der, that is correct if we set the REDIS_PROVIDER to the string REDISTOGO_URL instead of the environment variable..
The easiest way to get started would be to download this file https://unpkg.com/stimulus/dist/stimulus.umd.js and add it to your vendor/assets/javascripts folder.
Then add the following into the app/assets/javascripts/application.js
//= require stimulus.umd
I then would create a folder in the app/assets/javascripts called stimulus.
Within this new folder, I create another application.js file with the contents
const appStimulus = Stimulus.Application.start()
Following the Copy to Clipboard example that they have on the docs, you would create a copy_to_clipboard_controller.js within the stimulus folder with the contents
appStimulus.register("copy_to_clipboard", class extends Stimulus.Controller {
copy_text(e) {
e.preventDefault()
this.copy_address_field.select()
document.execCommand("copy")
}
get copy_address_field() {
return this.targets.find('copy_address_field')
}
})
Take note that the constant that I created was appStimulus and within each controller, we first call appStimulus.register(...)
This should get you started with getting Stimulus up and running in an existing application without adding Webpack. I don't think that I would add the complexities of Webpack in a application just for Stimulus. This would be my preferred route in an existing application.
Also, you may find that there are problems deploying to production. You may need to update the Uglifier gem to a later version and change the line in your config/environments/production.rb
# Compress JavaScripts and CSS.
config.assets.js_compressor = Uglifier.new(harmony: true)
You can to some degree. Remember that you will have to have the DOM elements already existing on the page so if any of the referred JS is adding elements, there may be some disconnect with Stimulus. However, a lot of it probably can be moved over. For example, if you have a date picker which has a lot of different attributes and customization, that would probably be a good candidate. A nested forms "Add Item" & "Remove Item" links may not be a good fit since you're adding elements to the DOM.