-
Notifications
You must be signed in to change notification settings - Fork 0
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
Get optimistic updates to work #1
Comments
Could you maybe use Meteor.methods({
'updateScore': function(playerId) {
if (this.isSimulation) {
const { simulateUpdate } = require('/path/to/simulateUpdate.js');
const { dispatch, getState } = require('/path/to/store.js');
const { collections: { players }} = getState();
dispatch(simulateUpdate(
'players',
playerId,
{ score: players[playerId].score + 5 }
));
} else {
const Players = require('/path/to/players.js');
Players.update(playerId, { $inc: { score: 5 } });
}
}
}); |
Yeah, that would actually work I think. Also, with the introduction of the I don't think I'll be working on this anytime soon though because the status of whether DDP will still be alive is in the air. |
Really? Where does meteor imply they're getting rid of it and what would they be replacing it with? |
They don't say explicitly, but implicitly with the rise of Apollo. |
I'll eventually implement it just for fun even if it goes nowhere. |
Unfortunately, getting optimistic updates was a fail because I tried to simulate the update before the method was called as you can see in my code that I commented out, but turns out that a client-side method stub needs to exist and the simulated call needs to take place inside the method stub in order to adhere to how the Meteor optimistic updates function under the hood. I had
saveOriginals
andretrieveOriginals
implemented but deleted the code. This is still doable and I didn't want to move forward until I get your feedback on you would want to consume it. So based on what I just said here are the issues:You need to create a client file only for the method stubs. This means you'd need the same method in a separate file in the server for the real updates. You can't put it in shared code space, otherwise, that means that the
Players
Mongo collection object would have to be imported into the client (unless you can import modules conditionally for server only and client only?), which we don't want and can't have because we created a DDP store definition by that name already. Also you would have to import the Redux store into the method, which looks kind of lame.All in all, I'm not so sure this is desirable.
I initially imagined this, but I don't think this is possible?
EDIT: With
reify
(Meteor 1.3.3) it should now be possible to do the below:The text was updated successfully, but these errors were encountered: