Change of screen with observables
See original GitHub issueI have an application, with login screen, choice of company and dashboard.
I had a redux structure that on my routes I did something like:
if (signedUser) {
if (signedCompany) {
return <AppRoutes />;
}
return <CompanyRoutes />;
}
return <AuthRoutes />;
It worked well, as it was with reducer and it redirected itself to the route if it changed these variables.
With the use of Watermelon, I tried to use getLocal, but it does not observe the variables as it is in the documentation.
So, I had to make an ‘auth’ scheme and model and put the columns ‘signed_user’, ‘signed_company’ to make it observable, the only way I thought to make it observable, this table would have only one record.
At login, create the record, and when choosing a company, update the record.
In my routes it is:
const enhance = withObservables(['auth'], ({ database }) => ({
auth: database.get('auth').query().observe(),
}));
export default withDatabase(enhance(Routes));
I happen to be looking at a list, and when it updates the record, it doesn’t.
How would you observe the update of the first record?
I tried to do otherwise, at login, create a user with id: ‘00000000-0000-0000-0000-000000000001’
And on the routes it would look like:
auth: database.get('auth').findAndObserve('00000000-0000-0000-0000-000000000001').observe(),
But the routes happen before and there is a registration error not found because it has not yet been created.
So, I would have to add this single record to the auth after creating the database. But I saw that it doesn’t have this native and I saw an issue that needs to do several things to create a database with preloading, as I’m new to this tool, I didn’t understand almost anything.
If anyone can help me, because something that seemed to be easy, is leaving me with no options.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9
@osvaldokalvaitir I think you need to query.
database.get('auth').query().observeWithColumns()
@jrounsav thank you so much! That was what was missing =)