Skip to content

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.

@StorytellerCZ
Copy link
Collaborator

@Grubba27 @jankapunkt I think we should merge this already.

@jankapunkt
Copy link

From my end this can be merged

@Grubba27 Grubba27 merged commit 50de8ee into master Jul 30, 2025
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.

7 participants