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
can not extend / override methods (for example _find) #3901
Comments
Hello @Leooo, I think this is an interesting use case but I'm not convinced that exposing Ember Data's internal finder methods is the best way to solve this problem. Ember Data's internals tend to change over time as new features are added and performance improvements are implemented. This causes code that is coupled to these internals to be brittle and break when new version of Ember Data get released. An alternate solution may be to identify what sort of public API(s) Ember Data could to expose to help you solve your problem without needing to access Ember Data's private methods. I'd like to know some more about your use case using multiple stores. Do you mind sharing a high level overview of how you are fetching records offline and when you want Ember Data to attempt to access the records via the network? |
It is very dirty as I have to deliver on my website and I can't spend the time needed to find the right solution (especially without being able to test other solutions based on modifying ED internals). I send different adapterOptions from the offlineStore methods on find-like methods, so that I build loading records instead of rejecting promises when getting relationships only (not for normal findRecord methods) :
Then in my localStorage adapter, I use the buildRecord options to sometimes build a loading record:
In DS.Model.extend:
Finally, in the emberSync mixin, I created a method |
I understand your explanation on why private methods are private. Still, I don't know how users can understand what ember-data does without being able to extend it for testing / logging purposes. |
I haven't been able to test this as I don't want to change ember-date in bower, but I think what could be changed is:
? |
Hi @Leooo, is this still relevant? |
@locks probably, but i suppose noone has time for it so you can close. L |
@Leooo hopefully the newer APIs and refactors help with this issue. Thanks for reporting, and let us know if you bump against this again! |
Hello,
I have the following use case: using two stores, one offline with LocalStorageAdapter, the other one online with ActiveModelAdapter, and something close to EmberSync to link both worlds.
When fetching records from the server, I don't always embed their relationships to improve the performance, so I'm storing offline records with relationship ids which are not fetched yet.
When it's time to load the relationships, offline first, Ember can not find them offline and unloads the empty records following https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store/finders.js, _find method l.36/37
I would like in some cases to not unload the empty records so that I'm able to access their ids and fetch them on the server, but here is the problem: impossible to override the _find method in https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/store/finders.js
I understand that in most cases, private methods are to be private and not giving access ensures they stay so, still for an open source framework, it is surprising to not be able to extend / override important classes / methods.
In my case for now, I hacked a whole bunch of other methods (store._findByInternalModel with different cases, depending on if we are using a store.findRecord or a model.get(relationship) etc.) to manage to satisfy my use case, but this is far dirtier than just overriding _find: As of now I'm creating loading records with corresponding deferred promises when getting relationships which are not yet fetched, which will be resolved once the server sends the results (not in the same loop, so I had to override flushPendingFetchFortype too..). But that means I have to take care when loading my relationships to possibly stuck pending promises, and make sure the corresponding records are fetched from the server - it would be better to send resolved / rejected promises when the record doesn't exist offline, as long as I'm still able to take note of the id to be fetched (not possible now with _find's unloadRecord).
Not sure my exact problem is clear, so to summarize: why can't finders store methods and others (I'm thinking about relationship helpers too) be made accessible / extendable by an Ember App.
Said another way: I have no clue how to extend ember$data$lib$system$store$finders$$_find, and I don't think this is possible, while I know how to do
import X from ember-data/lib/system/store/finders
for example. Is there a way to build ember-data in a way which would be more friendly for those who need to extend it?Thanks
The text was updated successfully, but these errors were encountered: