trailblazer / cells

View components for Ruby and Rails.
https://trailblazer.to/2.1/docs/cells.html
3.06k stars 236 forks source link

Options hash is same instance passed to each cell when using collections #498

Open samstickland opened 2 years ago

samstickland commented 2 years ago

All,

Is this deliberate here?

https://github.com/trailblazer/cells/blob/7b2a52d77aea9445ffa0df54e7a109f1ee2c836c/lib/cell/collection.rb#L34

I would prefer this to be @options.clone, as we have some cells that can be passed options or use their own default values (which might be dependent on the model). As we mutate the cells options, the same options then get used in the next render from the collection.

FWIW, we only have this idea of default values for options, because there's no actual control over how a cell is built. Something to think about for v5 perhaps.

apotonick commented 2 years ago

I think a quick solution would be to let Ruby do this by doing build(model, **options). In v5 we will enforce such an interface for constructors.

Ouch, that sounds like you had some fun figuring out why all collection items are rendered with the wrong options, or something along those lines? :laughing: