tronix117 [8:27 AM]
Hey guys, I'm working on a v3 adapter and I am trying to find a proper way to retrieve a mapper. I have access to a mapper and to the adapter instance, and would like to retrieve another mapper from the same store. When using v2, it was easy : Resource.getResource(), however on v3, my only workaround is forcing the user to give its store instance as an option of the adapter, which I doesn't like...
coryrobinson42 [2 days ago]
@tronix117 do you have a gist or code to share? (edited)
tronix117 [2 days ago]
I'm creating an adapter and need to initialize this way : const jsonApiAdapter = new JsonApiAdapter({store: store}) which I don't find very clean
coryrobinson42 [2 days ago]
Have you checked out the other adapters? Store is passed through the adapter as long as it's been registered with the store you're concerned with
coryrobinson42 [2 days ago]
I could be wrong, it looks like you can circumvent passing the store with your adapter instantiation.
tronix117 [2 days ago]
Are you sure ? Because how I see it in the code, the store calls adapters methods, but is never linked back to it, usualy the mapper doesn't need to know its store
tronix117 [2 days ago]
however in my case, the JsonApi structure needs an access to other mappers, thus an access to the common link between them : the store
tronix117 [2 days ago]
unless I missed something
coryrobinson42 [2 days ago]
hmm... I'll check it out a bit more later today and see if I can help more
tronix117 [2 days ago]
Thank you I appreciate it, unfortunately I don't think I have a proper way to do that, maybe @jmdobry can confirm that.
jmdobry [1 day ago]
Mappers defined via defineMapper have a reference to the store that defined them at Mapper#datastore.
jmdobry [1 day ago]
When A Mapper calls Adapter methods, the Mapper passes a reference to itself as the first argument, therefore, Adapter methods have access to the Mapper’s datastore
tronix117 [21 hours ago]
how did I missed that... Thanks a lot !
Chat extract about this matter: