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

RemoteId example #148

Open
nicosefer opened this issue Aug 23, 2017 · 3 comments
Open

RemoteId example #148

nicosefer opened this issue Aug 23, 2017 · 3 comments

Comments

@nicosefer
Copy link

Hi @dgeb
Could you please provide us an example with a remoteId use case? I couldn't find any, and i think it 's a hot topic, cause almost every offline approach ends in a sync with a remote server.
Thanks in advance!!

@nicosefer
Copy link
Author

Thanks to @dgeb for providing me this snippet:

import JSONAPISource, { JSONAPISerializer } from '@orbit/jsonapi';
import Orbit from '@orbit/data';
import fetch from 'ember-network/fetch';

export default class MySerializer extends JSONAPISerializer {
  resourceKey(type) {
    return 'remoteId';
  }
}

export default {
  create(injections = {}) {
    // Use `fetch` implementation from `ember-network`
    Orbit.fetch = fetch;

    injections.SerializerClass = MySerializer;
    injections.name = 'remote';

    return new JSONAPISource(injections);
  }
};

@coleyb
Copy link

coleyb commented Aug 6, 2018

@dgeb & @nicosefer ,

I appreciate your posts regarding the remoteId use case. I still seem to be having an issue when querying for a record. It seems that new uuid's are created in the deserializeResource method and when querying based on remoteId (server id) or id (ember orbit id) it seems to not find the record.

I believe this is due to this.keyMap.idToKey(type, resourceKey, id); in the resourceId method not finding the correct mapping. This makes sense considering the uuid I am querying changes every time the deserializeResource method is called.

Is there an expectation that the cache should be backed up with IndexedDB or similar for this use case? I knew it was option but was unsure if it was mandatory. Let me know if I can provide any additional information otherwise.

Thanks and appreciate the great work on this project!

@tchak
Copy link
Member

tchak commented May 25, 2019

We should move this content to guides. Contributions in doing so are welcome!

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

3 participants