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

Document "Octane" usage #413

Open
Turbo87 opened this issue Nov 18, 2019 · 7 comments · May be fixed by #428
Open

Document "Octane" usage #413

Turbo87 opened this issue Nov 18, 2019 · 7 comments · May be fixed by #428

Comments

@Turbo87
Copy link
Collaborator

Turbo87 commented Nov 18, 2019

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.

@dbollinger
Copy link

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

@alexlafroscia alexlafroscia linked a pull request Apr 5, 2020 that will close this issue
3 tasks
@esbanarango
Copy link

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

@runspired
Copy link

+1 on #428

@machty
Copy link

machty commented Sep 22, 2022

Seeing as how #428 still isn't merged, how are people using these APIs today? Is there a TS friendly way to do it?

@Turbo87
Copy link
Collaborator Author

Turbo87 commented Sep 22, 2022

@machty you might be interested in rust-lang/crates.io#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.

@spuxx1701
Copy link

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

@machty
Copy link

machty commented Jan 1, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants