Skip to content

Use the full power of Stimulus #5

Closed
@guillaumebriday

Description

@guillaumebriday

First thing first, I'm so happy to see this project! It's a huge deal for Stimulus and Symfony!! 👍

Under this title, I mean multiple things.

  1. Using disconnect callback

I think all controllers should use the disconnect callback to destroy instances. Like the Chart one.

If I dynamically remove the node from the DOM, the chart instance will remain loaded.

connect() {
  this.chart = new Chart(this.element.getContext('2d'), payload);
}

disconnect () {
  this.chart.destroy()
  this.chart = undefined
}
  1. Using data maps

Stimulus has a pretty handy API to deal with data: https://stimulusjs.org/reference/data-maps

It's cool because it's name-spaced by default, so it "forces" developer to use it in a more generic way. And it has methods to access datas.

I see lots of this.element.getAttribute('key') but they are not using data-maps

  1. Improve inheritence

All controllers dispatch a custom event "extends" controllers in a some way.

I think it would be more consistent to allow developers to extends these controllers like here with instance variables and so on instead of using custom event. Because sometime, it's useful to override the behavior.

Thanks a lot for this project!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions