ember-api-actions
ember-api-actions copied to clipboard
Document "Octane" usage
This Ember Octane the default will be to use ES6 classes for models. The README of this project will have to be adjusted to show how to use this addon with ES6 classes.
Example:
export default class MyModel extends Model { ... }
MyModel.prototype.myAction = collectionAction(...)
(thanks you to @rwjblue, who suggested the snippet above)
This is not exactly pretty though, so we might want to think about new API patterns that we can use in the Octane world in the future.
I'm at a point where I want to try using this add-on, so I'm going to use as-is without ES6 classes on my models for now -- but there's been a little bit of discussion in the ember-data discord about goals of modernizing this add-on.
https://discordapp.com/channels/480462759797063690/486549196837486592/695640101375705128
I think we definitely need #428 to landed before putting any Octane documentation 🙏
+1 on #428
Seeing as how #428 still isn't merged, how are people using these APIs today? Is there a TS friendly way to do it?
@machty you might be interested in https://github.com/rust-lang/crates.io/pull/5126. my plan is to extract that into a standalone addon once I have enough time and it's not using TS yet, but since it doesn't use decorators it most likely shouldn't be that hard to add types.
I'm very interested in seeing octane/typescript supported. :)
Just for posterity, here's the general pattern I'm using for a TypeScript + Octane context (Ember Data 3.27)
export default class MessageReceipt extends Model {
// ...
declare preview: (payload: any) => Promise<any>
}
MessageReceipt.prototype.preview = memberAction({
path: `preview`,
type: `put`,
})
tl;dr if you declare the method in the class body, you can define it on the prototype.