Ask A Question

Notifications

You’re not receiving notifications from this thread.

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 :)

Reply

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.

Reply

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.

Reply

Have a link to those comments by DHH about stimulus? Would love to hear his thinking.

Thanks!

Reply

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.

Reply

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.

Reply

Brilliant!

Reply
Lubomir Herko Lubomir Herko

You had my curiosity, now you have my attention :)

Reply

I'm very excited about Stimulus and can't wait to see where it goes!

Reply

Interesting Video! Chris - I am curious to know how Stimulus support external resources. For instance, Datatables, google charts ...

Reply

How would you structure your JS controllers? would every page have its own JS controllers?

Thanks! Love your videos!

Reply

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.

Reply
Jordano Moscoso Jordano Moscoso

For newbies the application.js has changed so visit the official site: https://stimulusjs.org/hand...

Reply

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))

Reply
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))
Reply
Any more episodes coming on Stimulus?
Reply
Hey Chris, FYI you have a spelling error in your code. 
  • 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?
Reply
Awesome video Chris! started using Stimulus in a work project and it's a very nice way to keep the JS organized and reusable. Thanks!
Reply

Awesome, as usual!

Reply

always appreciate the little humor, calling the app "stimulating" Lol

Reply

nice Introduction Cris, it looks like this is going to be a great feature for future rails applications comes

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.