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

Babel transform for assignment syntax (TypeScript support) #41

Open
buschtoens opened this issue Mar 26, 2019 · 0 comments
Open

Babel transform for assignment syntax (TypeScript support) #41

buschtoens opened this issue Mar 26, 2019 · 0 comments

Comments

@buschtoens
Copy link
Collaborator

buschtoens commented Mar 26, 2019

Related to #30 (comment) and #35.

Create a babel transform that converts the following assignment syntax to decorator syntax:

import { task, restartableTask } from 'ember-concurrency-decorators';

class Foo {
  @restartableTask({ maxConcurrency: 5 })
  bar = task(function*(this: Foo) {
    // ...
  });
}
import { restartableTask} from 'ember-concurrency-decorators';

class Foo {
  @restartableTask({ maxConcurrency: 5 })
  bar = function*(this: Foo) {
    // ...
  };
}

Using task in assignment syntax allows us to provide valid types for TypeScript.

Since we're applying a Babel transform now anyway, we can also remove the decorator usage at runtime completely by using Ember.defineProperty.

import { task } from 'ember-concurrency';
import { defineProperty } from '@ember/object';

class Foo {}

defineProperty(
  Foo.prototype,
  'bar',
  task(function*(this: Foo) {
    // ...
  }).maxConcurrency(5).restartable()
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant