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

willDestroy missed in documentation? #2914

Closed
svox1 opened this issue Mar 22, 2015 · 6 comments
Closed

willDestroy missed in documentation? #2914

svox1 opened this issue Mar 22, 2015 · 6 comments

Comments

@svox1
Copy link
Contributor

svox1 commented Mar 22, 2015

Hi,

I use store.willDestroy() to clean my models after the user is logged out. This works already fine.
I find this method after reading:
https://github.com/emberjs/data/blob/1.0.0-beta.15/packages/ember-data/lib/system/store.js#L1766

If this method is for public use, I was surprised that this method isnt in the documentation:
http://emberjs.com/api/data/classes/DS.Store.html

Or is this method not for public use?

Regards and thanks all Ember contributors!

@bmac
Copy link
Member

bmac commented Mar 23, 2015

The willDestroy comes form Ember.Object which the store extends (http://emberjs.com/api/classes/Ember.Object.html#method_willDestroy). It looks like when the Ember Data API doc are built they aren't pulling in classes from Ember itself. I wonder if it would be possible for the API docs to know about Ember classes they depend on without those classes showing up in the Ember Data sidebar.

@wecc
Copy link
Contributor

wecc commented Apr 13, 2015

@svox1 store.willDestroy() is not public API and not intended to be called manually. It's called by Ember internals when the store is being destroyed.

Could you explain more about your use-case? store.unloadAll(type) should be able to unload the models for you.

@svox1
Copy link
Contributor Author

svox1 commented Apr 13, 2015

I use store.willDestroy() to clean my models after the user is logged out.

I dont want to manually remove every model for himself (I have to clean all) and dont want to reload the whole application with

location.reload();

or something like this.

... its a Cordova Application.
So that is why I need a foreach like in willDestroy:

forEach(types, this.unloadAll, this);

I have create a pull request:
#2995
with this change, the method is still working in ember-data v1.0.0-beta.16.1

Or are there better alternatives with public methods?

@wecc
Copy link
Contributor

wecc commented Apr 13, 2015

Thanks for the PR! I'm afraid messing with willDestroy is not the right way to solve this problem, it's not supposed to be called at all.

Perhaps a better way would be to provide a public API for unloading all records of all types. We currently have methods for unloading a single record as well as all records for a specific type. I think a method to unload all records of all types would make more sense.

@bmac @fivetanley @igorT thoughts?

@igorT
Copy link
Member

igorT commented Apr 13, 2015

@wecc I just proposed the exact same solution in the other thread :)
willDestroy is a hook thats called when the store is being destroyed, it's not meant to be called directly.

@igorT igorT closed this as completed Apr 13, 2015
@svox1
Copy link
Contributor Author

svox1 commented Apr 14, 2015

I have create a pull request for this.
#2999
I hope everything is well.

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

No branches or pull requests

4 participants