Stimulus JS Framework Introduction Discussion
I'm literally figuring out StimulusJS right now on an app, and I was hoping you would do a screencast on it soon and save me some time! Awesome timing :)
Hit me up with your questions! I'm still learning it too, but the good news is that it's pretty straightforward so there isn't _too_ much to learn.
Great intro! What impresses me is how basecamp remains an incubator for code concepts thereby battle testing it before releasing to the wild. While programming is a joy for many of us, it is also how we make a living. I appreciated some of DHH's comments about stimulus and I truly appreciate their pragmatic views. I also am impressed how they rethink conventions like using DOM for state, managing a monolith, and supporting the progressive web development. This looks to make a nice addition to the toolset.
Have a link to those comments by DHH about stimulus? Would love to hear his thinking.
Thanks!
Thanks for the interesting video. For a project of mine I used AngularJS (the original 1.x branch) in a similar way basecamp now proposes to use StimulusJS. What I liked about AngularJS in this context was the ability to offer form validation and to go as deep as I want it to go on demand. Right now what I would love to see in further stimulus releases would be something to handle form validation out of the box and some other convenience things every app needs.
I get the feeling that Basecamp won't build out those kinds of features and will keep this generic, but it is the perfect opportunity to build a library on top of stimulus to make validations easy I would imagine.
Interesting Video! Chris - I am curious to know how Stimulus support external resources. For instance, Datatables, google charts ...
How would you structure your JS controllers? would every page have its own JS controllers?
Thanks! Love your videos!
Basically just one controller per feature. You should never do page specific JS or CSS because that means you can't move your features to different pages on your site later on which inevitably always happens.
For newbies the application.js has changed so visit the official site: https://stimulusjs.org/hand...
Looks like if you've loaded version >=1 of Stimulus, there are a few changes in the installation. (See handbook at https://stimulusjs.org/hand...
Setup in application.js should look like:
import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"
const application = Application.start()
const context = require.context("./controllers", true, /\.js$/)
application.load(definitionsFromContext(context))
import { Application } from 'stimulus' import { definitionsFromContext } from 'stimulus/webpack-helpers' const application = Application.start() const controllers = require.context('./controllers', true, /\.js$/) application.load(definitionsFromContext(controllers))
- Applicatoin instead of Application
- stumulus instead of stimulus.
- constrollers instead of controllers
- $ needed in .js regex
import { Applicatoin } from 'stimulus' import { autoload } from 'stumulus/webpack-helpers' const application = Application.start() const contsrollers = require.context("./controllers", true, /\.js$/ )
Even after I did this I had an error `TypeError: Object(...) is not a function`. I reviewed the stimulus installation guide and changed to:
import { Application } from "stimulus" import { definitionsFromContext } from "stimulus/webpack-helpers" const application = Application.start() const context = require.context("./controllers", true, /\.js$/) application.load(definitionsFromContext(context))
It looks like it should do the same thing. Funnily enough I tried
import { Application } from "stimulus" import { autoload } from "stimulus/webpack-helpers" const application = Application.start() const controllers = require.context("./controllers", true, /\.js$/) application.load(autoload(controllers))
And it had the same error (all I did was rename 'context' to 'controllers' and 'definitionsFromContext' to 'autoload'
Maybe the name 'controllers' has become reserved?
nice Introduction Cris, it looks like this is going to be a great feature for future rails applications comes