biosustain / potion-node

TypeScript client for Flask-Potion
MIT License
8 stars 5 forks source link

feat: implement async Item attributes #2

Open rolandjitsu opened 8 years ago

rolandjitsu commented 8 years ago

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.

rolandjitsu commented 8 years ago

Reopen, #1 was supposed to be closed instead.

rolandjitsu commented 6 years ago

Partial impl. of the feature is published on the next tag on NPM. See potion-node#next for current progress.

Current issues with using @async props: