npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

aurelia-async-bindable-bluebird

v1.0.0

Published

An Aurelia decorator for the binding of async getters.

Readme

aurelia-async-bindable

How It Works (This Is IMPORTANT)

READMEs don't usually begin with this kind of information. However, with asyncBindable, understanding how it works is really important. If you use it incorrectly, you may have interesting things happen to you!

asyncBindable is a powerful decorator that can be used to bind asynchronous getters to your aurelia views. It should be used along with a getter on your view model that returns a promise.

Internally, the decorator does two things:

  1. It transforms your getter:
    • It memoizes the return value (based on the dependencies - more on this later)
    • Wraps your getter in a function that returns appropriate values depending on the state of the promise returned by your getter.
  2. It sets up an additional property on your view model and tells @computedFrom to watch that property.

When your promise resolves, asyncBindable changes the property that @computedFrom is watching and retriggers any dependant bindings.

Why memoize?

Async bindings are particularly sensitive to being called multiple times. This is because they often contain network calls which we only want executed once. If asyncBindable is used along with computedFrom, the computedFrom dependencies are taken into account in the memoization.

Implications

There are some important implications you should take away:

  1. asyncBindable by default will only make a call to the getter that you declared once. It does not magically know when to call your getter again. You need to tell it when to reevaluate the getter (see this section).
  2. Because asyncBindable is using computedFrom internally, it is only natural that you can use them together (see this section) However, when using them together, order is important, the asyncBindable decorator must be declared first.
  3. Don't worry about dirty checking. Generally, when you bind to a regular getter, aurelia will have to resort to dirty checking to update the binding (because it has no way of knowing which properties to observe for the update). However, because asyncBindable is using computedFrom internally, that automatically means that Aurelia will NOT use dirty checking to update any dependent bindings.

Using The Decorator

Simple Use

The simplest use case is if you want to bind the results of a network call:

@asyncBindable()
get listItems() {
    return remoteEndpoint.call()
        .then(response => response.list);
}

Then, simply use in your view like so:

<ul>
    <li repeat.for="item of listItems">${item.label}</li>
</ul>

Options

There are three options:

@asyncBindable({
    pendWith: 'Loading...', // pendWith takes a primitive value. As long as the promise is pending, this primitive will be provided to Aurelia.
    resolveWith: resolvedValue => resolvedValue.slice(0, 10), // resolveWith can be a function like this example or a primitive.
    rejectWith: rejectionErr => rejectionErr.message // rejectWith can be a function like this example or a primitive.
})

Using along with the computedFrom decorator

A very common use case is to need to use this decorator along with @computedFrom. For example, suppose you are showing a list of tasks for a specific story. A user can change the story that is selected, and the list of tasks needs to auto update:

View Model:

@asyncBindable()
get stories() {
    return storiesEndpoint.get();
}

@asyncBindable()
@computedFrom('storyId')
get tasks() {
    return tasksEndpoint.get(this.storyId);
}

View:

<select value.bind="storyId">
    <option repeat.for="story of stories" value.bind="story.id">${story.title}</option>
</select>

<table>
    <tr repeat.for="task of tasks">
        <td>${task.title}</td>
    </tr>
</table>

PLEASE NOTE: When using asyncBindable in conjunction with computedFrom, the asyncBindable declaration must come first.

Manually Refreshing Dependent Bindings

Suppose you want to manually retrigger bindings dependent on a asyncBindable decorated getter. For instance, in the example above, suppose you want to refresh the tasks without the storyId changing.

A solution to this is to just add a dependency that you manually control like so:

@asyncBindable()
@computedFrom('storyId', 'tasksRefreshes')
get tasks() {
    return tasksEndpoint.get(this.storyId);
}

tasksRefreshes = 1;

Now, if you want to refresh the tasks:

someMethodThatNeedsToRefreshTasks() {
    // Do stuff.
    this.tasksRefreshes++;
}

Transpiling

To transpile to dist:

npm start -- transpile