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

A real world example(s)? #90

Closed
MichalBryxi opened this issue Jul 25, 2021 · 4 comments
Closed

A real world example(s)? #90

MichalBryxi opened this issue Jul 25, 2021 · 4 comments

Comments

@MichalBryxi
Copy link
Contributor

I'm having a hard time understanding what is a resource and when to use one. I think an example that shows a case where you use this library to solve standard problem would be nice.

@NullVoxPopuli
Copy link
Owner

NullVoxPopuli commented Jul 25, 2021

That's fair. 🤔
I just released this a bit ago: https://github.com/NullVoxPopuli/ember-array-map-resource
But that's very niche / specific. 🙃

Maybe something interacting with ember-data would be a good example to put to the ember-resources README.

Like,

class extends Component {
  @service store;

  someRecord = useFunction(this, (, id) => {
     return this.store.findRecord('some-record', id);
  }, () => this.args.id);
}

someRecord.value (.value is required for function-resources) would be:

  • undefined initially
  • will not call findRecord until someRecord.value is accessed
  • "eventually" be an ember-data Model
  • if @id / this.args.id change, the function is run again, someRecord.value keeps its old value until the function re-resolves.

I'm sure the README phrasing can be better, but the gist is that they solve the problem of "reactive lazy data that resolves eventually".

Like, without the resource, you'd need to find a way to call a function that calls findRecord yourself.
And then you'd need to also figure out a way to re-call that function when your @id changes.

Does that help? 🤔
I can keep coming up with examples, if not 🙃

@NullVoxPopuli
Copy link
Owner

Here are some additional examples: https://github.com/NullVoxPopuli/ember-data-resources/

MichalBryxi added a commit to MichalBryxi/ember-resources that referenced this issue Aug 8, 2021
- To give an example of how to use this ember-resources
- To make sure people are not reinventing the wheel
- To encourage people to create their own addons
MichalBryxi added a commit to MichalBryxi/ember-resources that referenced this issue Aug 8, 2021
@MichalBryxi
Copy link
Contributor Author

I think you covered (at least mine) most pressing questions. Now I think there is a value of cross linking ember-resources and ember-data-resources in the documentation to show people how things can be done. I created #120 for that.

@MichalBryxi
Copy link
Contributor Author

This one can be probably closed now.

MichalBryxi added a commit to MichalBryxi/ember-resources that referenced this issue Aug 8, 2021
- To give an example of how to use this ember-resources
- To make sure people are not reinventing the wheel
- To encourage people to create their own addons
MichalBryxi added a commit to MichalBryxi/ember-resources that referenced this issue Aug 8, 2021
NullVoxPopuli added a commit that referenced this issue Aug 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants