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

Support asynchronous (promised-based) custom matchers #138

Open
bradvogel opened this issue Mar 4, 2018 · 2 comments · May be fixed by #157
Open

Support asynchronous (promised-based) custom matchers #138

bradvogel opened this issue Mar 4, 2018 · 2 comments · May be fixed by #157
Labels

Comments

@bradvogel
Copy link

For our use case, we'd like to implement custom expressions that make database calls. An example of what we'd like to do (that doesn't work today):

sift.use({
  $existsInDb: async function(expectToExist, name) {
    const existsInDb = !!(await db.users.findOne({ name }));
    return existsInDb === expectToExist;
  }
});

const result = await sift({ $existsInDb: true }, ['bob', 'ben', 'brad']);
@skeggse
Copy link

skeggse commented Apr 11, 2019

FYI: we forked sift.js and implemented async support in mixmaxhq#1.

@crcn crcn linked a pull request Jun 23, 2019 that will close this issue
1 task
@crcn
Copy link
Owner

crcn commented Jun 23, 2019

Just starting on this functionality in #157. The API will likely be:

const asyncFilter = sift({ $existsInDb: true }, {
  operations: {
    async $existsInDb(expectToExist, name) {
      const existsInDb = Boolean(await db.users.findOne({ name }));
      return existsInDb === expectToExist;
    }
  }
});

const results = await Promise.all(['bob', 'ben', 'brad'].filter(asyncFilter));

@crcn crcn added the feature label Jun 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants