In my opinion events (or function props) and props mean loose coupling as they only know each others interface and shared state is a strong coupling. Why do you think they know about each other? Yes, they know each other's interface, but it's necessary to communicate.
With other frameworks (Vue, Angular, React) I've found it easy to test events or function props, what I was missing is the $on method.
Item knows about a remove operation, which means it "knows" that it exists in some kind of container (List or otherwise).
Not saying I know of a better solution or that I wouldn’t write it that way myself... just that I’m a little wary of dispatch and I’d keep my eyes open for opportunities to design it differently.
Another point: unless I’m mistaken, $on is part of the internal Svelte API so if you use it, you have to be prepared to figure out a new solution if/when the maintainers break this one 🤣
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks for the example, I'll try it out tomorrow.
In my opinion events (or function props) and props mean loose coupling as they only know each others interface and shared state is a strong coupling. Why do you think they know about each other? Yes, they know each other's interface, but it's necessary to communicate.
With other frameworks (Vue, Angular, React) I've found it easy to test events or function props, what I was missing is the
$on
method.Item
knows about aremove
operation, which means it "knows" that it exists in some kind of container (List
or otherwise).Not saying I know of a better solution or that I wouldn’t write it that way myself... just that I’m a little wary of
dispatch
and I’d keep my eyes open for opportunities to design it differently.Another point: unless I’m mistaken,
$on
is part of the internal Svelte API so if you use it, you have to be prepared to figure out a new solution if/when the maintainers break this one 🤣