-
-
Notifications
You must be signed in to change notification settings - Fork 298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue using d.listen #77
Comments
Listeners are all called inside |
So I'm probably doing this wrong..
I'm just using db1 as the single database used by the application conn is set after retrieving schema and initialising:
db1 is set after each transaction:
Render gets value of actual db (db1) directly:
So in summary I'm viewing conn as something that doesn't change after creating the db, db1 is forced to change after each transaction - and db1 is then used directly for React queries |
Yep, you don’t need |
It looks like there may be a possible race condition in d.listen - or that I am misunderstanding how to use it (quite possible).
I have one function A which transacts data to a db using data from a websocket connection:
function listener(args, kwargs) {
console.log('** Listener called', kwargs[':tx-data']);
d.transact(conn, kwargs[':tx-data']);
db1 = d.db(conn);
}
I have a separate reporter function B which generates an event for react js to trigger a re-render.
d.listen(conn, function(report) {
console.log('**Reporter heard and declaring showtime here is my report', report);
document.dispatchEvent(new CustomEvent('SHOWTIME'));
});
Re-rendering triggers a query from React and isn't always working - it turns out the problem is the data which the reporter thinks should be in the DB (from the the report tx_data) isn't always - so as if the listener trigger isn't when the transaction actually finishes.
Confusing is that moving the 'showtime' event dispatch to the end of A works.
This would make sense if d.transact was blocking, but if that was the true then I wouldn't expect d.listen to run until the transaction was finished.
If d.transact is non-blocking then I would expect to see the same issue with the event dispatch in either place - and I don't.
Any thoughts / suggestions appreciated.
The text was updated successfully, but these errors were encountered: