Skip to content
This repository has been archived by the owner on May 21, 2021. It is now read-only.

Issue #14 - Replace db transaction used when saving flattrs with a redux saga #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

erikvold
Copy link
Collaborator

@erikvold erikvold commented Feb 2, 2018

No description provided.

@erikvold erikvold self-assigned this Feb 2, 2018
@@ -39,7 +39,7 @@ function addAttention(tabId, url, addedAttention, isManual)

if (addedAttention >= getRemainingAttention(entity, oldAttention))
{
yield flattrManager.submit({
flattrManager.submit({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're no longer waiting for the submission to succeed before continuing with the next steps. Why wouldn't this be an issue?

At least I could imagine that this leads to inconsistencies in the UI (e.g. attention bar filling up but flattr count not increasing).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least I could imagine that this leads to inconsistencies in the UI (e.g. attention bar filling up but flattr count not increasing).

At the moment if there is an error then nothing in the UI changes, is that better? I don't think it is, I think it's worse because we're just hiding errors from the user.

Also we reduce the chances of an error here because we make sure that only one save is performed at a time, and so we don't depend on transactions (which can cause errors).

Finally we at least have the chance to correct the error here, with logic that can detect error states like the one that you pointed out above (Pretty sure I didn't do this here yet, but I think that would be a good follow up issue).

continue;
}

yield call(saveFlattrs, {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detail: saveFlattrs() doesn't expect any arguments.


for (let {entity, tabId, title, type, url} of saving)
{
let entry = yield call(save, {entity, tabId, title, type, url});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if save() fails? We do have SUBMIT_FLATTRS_FAILURE as well as SAVE_TIMESTAMP_FAILURE for the other cases for which we use Redux.

};
exports.flattrs = flattrsReducer;

const getFlattrs = (state) => ((state || {}).flattrs || {});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I'd suggest writing this as (state = {}) => (state.flattrs || {}) to make this part a bit easier to read by avoiding the inner brackets.

@@ -0,0 +1,100 @@
"use strict";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I noticed that this is almost an exact copy of test/tests/reducer-flattrs-submit.js so what about adding an abstraction so that we don't have so much duplicated code lying around?

{
return new Promise((resolve) =>
{
setTimeout(resolve, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion: I assume you'd like to use setImmediate() here instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why I would want to resolve a promise multiple times. It does look like I can get away with simply using Promise.resolve() here instead.

assert.deepEqual(state.flattrs.save.saving, flattrsOne);

yield saga.waitFor(SAVE_FLATTRS_SUCCESS, true);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detail: Please add an intermediate assert step here to avoid mixing together the effects of SAVE_FLATTRS_SUCCESS and SAVE_FLATTRS.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants