hotwired / stimulus

A modest JavaScript framework for the HTML you already have
https://stimulus.hotwired.dev/
MIT License
12.67k stars 420 forks source link

Feature Request: Interacting between uncoupled controllers by id #112

Closed magynhard closed 6 years ago

magynhard commented 6 years ago

I like the simple approach of StimulusJS, but I painfully miss a solid feature to interact easily between controllers.

What about just defining ids to the data-controller attributed HTML element and write some custom code like this on the specific web page:

function addDateToNotePad() {
  let dateSelector = Stimulus.getComponentById('date_selector');
  let selectedDate = dateSelector.date;

  let notepad = Stimulus.getComponentById('notepad');
  notepad.add(selectedDate);
}

I think that would be an very easy approach to solve this.

What do you think about that?

Spone commented 6 years ago

Hello, did you see #35?

magynhard commented 6 years ago

Thanks for your reply.

Yep, i had a look at it last week.

It forces me to wrap each component of same type with another componenct, which creates complexity as I'm get used by Angular.

For example i have two components of the same type, both must be wrapped with another controller.

I think direct access on the top level of my JavaScript - or at least a inerheritet "ConnectionClass" would be a much much simpler approach. IDs give me structure and i can easily follow the code.

Thinking like a chess board, where the chessmens are the components and the board is the landscape where i can access interact between them. Easy, simple, joyful.

The nested Components does only make sense for me, if i create another component that is a composition of a few other components. There they ensure that i can put the component where i want to.

But on specific pages, IDs and specific interaction code is what i need and want to.

javan commented 6 years ago

Thanks for the feedback. As noted in https://github.com/stimulusjs/stimulus/issues/35#issuecomment-355311491, this is on our radar. Feel free to continue discussing there.