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

Feature mongo async #35

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open

Feature mongo async #35

wants to merge 37 commits into from

Conversation

Grubba27
Copy link
Contributor

@Grubba27 Grubba27 commented Sep 5, 2022

This PR is about updating the tutorial to start using the mongo API introduced in Meteor 2.8

@StorytellerCZ and @jankapunkt, do you guys have any good examples of using promises? I thought of something like with Tracker.autorun, as seen in this forum post, but I lack some context of Blaze.

Here is a sample of what I did before realizing that it does not accept promises as return value:

// with new Mongo Async API 
async tasks() {
    const instance = Template.instance();
    const hideCompleted = instance.state.get(HIDE_COMPLETED_STRING);

    const { pendingOnlyFilter, userFilter } = getTasksFilter();

    if (!isUserLogged()) {
      return [];
    }

    return await TasksCollection.find(
      hideCompleted ? pendingOnlyFilter : userFilter,
      {
        sort: { createdAt: -1 },
      }
    ).fetchAsync();
  }

// Old one

tasks() {
    const instance = Template.instance();
    const hideCompleted = instance.state.get(HIDE_COMPLETED_STRING);

    const { pendingOnlyFilter, userFilter } = getTasksFilter();

    if (!isUserLogged()) {
      return [];
    }

    return TasksCollection.find(
      hideCompleted ? pendingOnlyFilter : userFilter,
      {
        sort: { createdAt: -1 },
      }
    ).fetch();
  }

@jankapunkt
Copy link

Hey @Grubba27 we still have the issue, that Blaze helpers don't accept Promises. The linked issue is this one here: meteor/blaze#364

@StorytellerCZ from that perspective we should tackle the above mentioned issue asap, so this PR here can continue. WDYT?

@Grubba27
Copy link
Contributor Author

Grubba27 commented Sep 8, 2022

I think is a must! What are the limitations for that issue to be solved? Do we have any possible implementations? Maybe go with something like what Svelte does with its async API but make it idiomatic for Blaze?

{#await promise}
	<p>...waiting</p>
{:then number}
	<p>The number is {number}</p>
{:catch error}
	<p style="color: red">{error.message}</p>
{/await}

@StorytellerCZ
Copy link
Collaborator

@jankapunkt I currently don't have usage of Blaze necessary to properly evaluate this PR, so I'll leave this to your discretion.

@yacinec
Copy link

yacinec commented Sep 20, 2024

Hi guys,
I know this PR is pretty old but I'm currently following the tutorial and I've encountered problems with the async.
I've just stumbled across this PR that corrects the code examples on each step. It would be great if it could be merged, as it can be confusing with the current version of the tutorial.

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

Successfully merging this pull request may close these issues.

4 participants