ember-api-actions icon indicating copy to clipboard operation
ember-api-actions copied to clipboard

Document "Octane" usage

Open Turbo87 opened this issue 5 years ago • 7 comments

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.

Turbo87 avatar Nov 18 '19 16:11 Turbo87

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

dbollinger avatar Apr 03 '20 14:04 dbollinger

I think we definitely need #428 to landed before putting any Octane documentation 🙏

esbanarango avatar Jul 23 '20 04:07 esbanarango

+1 on #428

runspired avatar Jun 10 '21 21:06 runspired

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 avatar Sep 22 '22 19:09 machty

@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.

Turbo87 avatar Sep 22 '22 23:09 Turbo87

I'm very interested in seeing octane/typescript supported. :)

spuxx-dev avatar Oct 12 '22 14:10 spuxx-dev

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.

machty avatar Jan 01 '24 00:01 machty