Skip to content
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

Add a new example project with advanced fpdart usecases + update readme #134

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

Biplab-Dutta
Copy link

No description provided.

@SandroMaglione SandroMaglione added the documentation Improvements or additions to documentation label Sep 3, 2023
@Biplab-Dutta
Copy link
Author

Hi @SandroMaglione. Is there any prerequisite for this PR to get merged? If so, please let me know.

Copy link
Owner

@SandroMaglione SandroMaglione left a comment

Choose a reason for hiding this comment

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

@Biplab-Dutta could you expand the README of the example app? Based on it, I will then check the code from a user perspective and see if something is unclear or needs clarification.

After that this can be merged.

Copy link
Owner

Choose a reason for hiding this comment

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

Could you expand the README of the app?

Since this is an example project, the README should guide people on how to read and understand the implementation. This should highlight things like:

  • Features of the app
  • Package dependencies (and the reason why they are used)
  • Overview of the file structure
  • Entry point of the app and guidelines on how to read the code
  • How fpdart specifically is used in the project

Copy link
Author

Choose a reason for hiding this comment

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

Got it. Shall do it on my weekend.

Copy link
Author

Choose a reason for hiding this comment

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

Done
701295e

@SandroMaglione
Copy link
Owner

@Biplab-Dutta are you still interested in working on this PR?

@Biplab-Dutta
Copy link
Author

Biplab-Dutta commented Dec 7, 2023

Hi @SandroMaglione.
I got ill recently so i had been hospitalized. And i completely forgot about this PR. Sorry.
Let me work on it today. Thanks

@Biplab-Dutta
Copy link
Author

Hi @SandroMaglione. Please check the README for the new example project.

Copy link
Owner

@SandroMaglione SandroMaglione left a comment

Choose a reason for hiding this comment

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

Added some comments and suggestions on fpdart code.

After reading the code from a user perspective I am now thinking that this app has too much no-fpdart code. From a user perspective that is looking for fpdart examples having many files is not much help.

Do you think you can reduce the scope and leave mainly fpdart-related files? Otherwise I think it would be better to not include the project directly inside fpdart's examples

Comment on lines 18 to 27
Task<Unit> upsertDetail(DetailDTO detailDTO) {
final txn = _isar.writeTxn<Unit>(
() async {
await _isar.detailDTOs.put(detailDTO);
return unit;
},
silent: true,
);

return Task(() => txn);
Copy link
Owner

Choose a reason for hiding this comment

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

This use of Task is incorrect. The function should be declared inside Task, otherwise is not pure:

Task<Unit> upsertDetail(DetailDTO detailDTO) => Task(() { ... })

Copy link
Author

Choose a reason for hiding this comment

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

Done


await _(_headerCache.saveHeader(header).toTaskEither());

final html = response.data!;
Copy link
Owner

Choose a reason for hiding this comment

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

This could potentially fail (using !). I would validate this instead of using ! to make sure the API does not return invalid data.

Copy link
Author

Choose a reason for hiding this comment

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

In my case, the data could not have been null if the program flow reached there. But change made

fullPathToMarkdownFile,
);

await _(_headerCache.saveHeader(header).toTaskEither());
Copy link
Owner

Choose a reason for hiding this comment

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

Nesting calls using _ may cause problems (read here)

Copy link
Author

Choose a reason for hiding this comment

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

In my case, how can I have my code refactored? I tried but didn't succeed. I'd appreciate your help on this one.

Comment on lines +66 to +69
return right(ModifiedRemoteResponse(html));
}

return right(const UnModifiedRemoteResponse());
Copy link
Owner

Choose a reason for hiding this comment

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

Since you are always returning right this indicates that this TaskEither never fails, better to use Task then

Copy link
Author

Choose a reason for hiding this comment

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

Something like this?

.flatMap(
  (response) {
    return Task<RemoteResponse<String>>.Do(
      (_) async {
        if (response.statusCode == 200) {
          final header = GithubHeader.parse(
            id,
            response,
            fullPathToMarkdownFile,
          );

          await _(_headerCache.saveHeader(header));

          final html = response.data!;
          return ModifiedRemoteResponse(html);
        }

        return const UnModifiedRemoteResponse();
      },
    ).toTaskEither();
  },
)


return remoteResponse.when(
noConnection: () async {
final dto = await _(_localService.getDartDetail(id).toTaskEither());
Copy link
Owner

Choose a reason for hiding this comment

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

Same as above, better not use _ in a nested function

Comment on lines +35 to +36
final cachedData = await _(
_localService.getDartDetail(id).toTaskEither(),
Copy link
Owner

Choose a reason for hiding this comment

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

_ nested

_remoteService.getDartChangelogDetail(id),
);

return remoteResponse.when(
Copy link
Owner

Choose a reason for hiding this comment

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

This returns an async response. You should always use _ when executing async functions inside Do

Copy link
Author

Choose a reason for hiding this comment

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

I tried but couldn't figure out way to refactor my code. I'd really appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants