How to Make a Decorator Accessible from a Plugin

I am writing an Aurelia plugin and need consumers to have access to a decorator function which is defined within the plugin. How do I make it accessible to the plugin’s consumers?

1 Like

Essentially you just export it. See here for the Stores connectTo decorator. https://github.com/aurelia/store/blob/master/src/decorator.ts#L21

2 Likes

Thanks! I figured it was easy.

1 Like

I got sidetracked and just got around to trying this out. I’m using the current cli plugin structure with dev-app and src directories. My decorator is in src/decorators/my-decorator.js. When I try to import it in a dev-app class by referring to the plugin as “resources”, like this:

import {myDecorator} from 'resources/decorators/my-decorator';

I get an error stating “SyntaxError: Unexpected token ‘{’. import call expects exactly one argument.”

If I move my decorator file into the dev-app directory and import it like this:

import {myDecorator} from './my-decorator';

It works fine.

1 Like

That SyntaxError looks very strange in context of 'resources/...', can you share a small repo to reproduce it?

1 Like

I got no issue on your resources import.

1 Like

My decorator begins with:

import {bindable, bindingMode} from 'aurelia-framework';

I assume the error is referring to this. Could you try adding this import statement to your my-decorator.js file?

1 Like

Never mind! I just realized I needed to terminate au run and rerun it! Now all is well. Thanks for everyone’s help.

2 Likes