Is this a correct use of component?

#1

Hi, all, I’m looking at an entity that holds some numbers, and then processes those numbers using a function named by another attribute of the entity. So, like:

–mathy
----A [int]
----B [int]
----F [component ref]

So, if “A” is 9, and “B” is 7, and F is “Sum”, if you ask for a result for this entity, you’d get 16. If F were switched to “Product”, you’d then get 63. If “Different”, you’d get 2, and so on.

The person who designed the entity made F a component, and that seems inappropriate to me. I can’t see it hurting anything but it seems wrong.

My reasoning is that the docs for component say they’re for entities that don’t exist outside of their parent entity, like line items on an invoice. While it’s true that the functions themselves are meaningless without a parent entity, the same functions are used in many different entities. I.e., lots of entities will use the same “Sum” function, and lots will use “Product”, and so on. You’d never delete a function even if no entities were currently referencing it.

Thoughts?

0 Likes

#2

:db/isComponent mechanically means that :db/retractEntity will also retract it’s components (and maybe some other things) so I think you’ve made a strong argument that F should not be :db/isComponent.

0 Likes

#3

Yikes!

So if Entity 1 points to “Sum”
And Entity 2 points to “Sum”
And I retract Entity 1…

“Sum” goes away? :scream:

0 Likes