Skip to content

Returning Promise<undefined> from getter triggers update #28

@traed

Description

@traed

Hi!

I don't known if the docs are wrong or if this is not working as intended, but when running this example:

const posts = asyncable(async ($path, $query) => {
    if ($path.toString() === '/posts') {
      const res = await fetch(`/posts?page=${$query.params.page || 1}`);
      return res.json();
    }
  },
  null, 
  [ path, query ]
);

... the store will always be updated. That is because an async function (the getter in this case) will always return a Promise. In this case either the return value of res.json() or a Promise<undefined>. If we instead do this:

const posts = asyncable(($path, $query) => {
    if ($path.toString() === '/posts') {
      return fetch(`/posts?page=${$query.params.page || 1}`).then(res => res.json());
    }
  },
  null, 
  [ path, query ]
);

... it will work as stated in the docs because now the return type is either a Promise or undefined (not Promise<undefined>).

IMO this shouldn't matter. If the getter returns either undefined or Promise<undefined> no update should be triggered.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions