Description
We have seen that the state.source.get()
function and the state.source.data
object, while crucial to understand how source
and Frontity works, are hard to understand because:
- It’s hard to know that
state.source.get()
returns things stored instate.source.data
because their names don’t correlate. - By just inspecting the state, it’s really hard to know that you should always use
state.source.get()
and never accessstate.source.data
directly. - Both the
get
and thedata
names don’t tell anything to the user about the type of data that they will return. Is it all the data or is it just a part?
User Stories
As a Frontity beginner
I want to quickly understand how to access information about URLs
so that I can write my own logic faster
Possible solution
We should:
- Use a single name for both, so it’s clear that they are related.
- Change the name to show that it doesn’t contain all the data, only some information about that link.
My proposal is:
- Use
state.source.info()
:
state.source.info("/some-link");
- Use
state.source.infoObjects
orstate.source.infoData
to store the objects.
That way, when people inspect state.source
in the console it will be easier to make a mental connection between them.
Backwards compatibility
To keep backward compatibility, we can:
- Keep
state.source.get()
(but add a deprecation warning). We can even use derived state to returnstate.source.info
. - Keep
state.source.data
for old handlers that write directly there.state.source.info
should look first instate.source.infoObjects
but if the info is not found there, it should still look instate.source.data
.