Skip to content

feat: implement async Item attributes #2

@rolandjitsu

Description

@rolandjitsu

A user should be able to mark certain Item properties as async and when references are resolved, these async properties should be skipped. Instead of resolving these async properties, their values should be promises that are not resolved unless their getter gets called.

Example:

import {Potion, Item} from 'potion';

const potion = new Potion();

@potion.registerAs('/bar')
class Bar extends Item {}

@potion.registerAs('/foo')
class Foo extends Item {
    @async
    bar: Bar;
}

const foo = Foo.first();

// At this point, the `bar` reference is not resolved
foo.then((item) => {
    // Now Potion will resolve the `bar` reference because the getter for `bar` is accessed
    return item.bar;
});

In case of usage with Angular 2+, it would integrate well with the async pipe:

<p>{{foo.bar | async}}</p>

This feature can be useful when we do not want to resolve every reference to a resource if there are too many and/or if they are not used anywhere.

NOTE: It may not be possible to use the getter for a property on Item, this needs further investigation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions