pmndrs / koota

🌎 Performant real-time state management for React and TypeScript
127 stars 5 forks source link

Automatically set change detection for traits that are being observed #16

Open krispya opened 3 weeks ago

krispya commented 3 weeks ago

Right now change detection is set per updateEach call manually, default off. The proposal is to make change detection be on, off, or auto instead of a boolean, with default being auto. If auto then it would follow these rules:

There was suggestion to make this even more specific, per entity per trait. There is no API for that currently (you can observe all entities for a given trait, not specific entities, and then filter for specific entities) so this should be opened as another issue.

Ctrlmonster commented 3 weeks ago

Looks good. Yeah I think entity + trait can be an implementation detail eventually. Since the public listening API requires you to pass an Entity in all cases anyway (unless I'm missing some?). Storing the tuple (trait, entity) in the tracking list should greatly reduce the number of comparisons and thus improve perf, making auto a save option in basically all cases. But since this issue is about the updateEach API, I think it's good as it is 👍

krispya commented 3 weeks ago

Only the React API makes you pass in an entity. The core API does not (onChange) and neither does tracking queries using the Changed modifier.

Ctrlmonster commented 3 weeks ago

I see. Okay let's put that discussion in another issue, since this is pretty much agreed on.