Hi.
I’m need to setup a model layer where a Type’s connection has the following capabilities:
- when a new instance is saved (or an existing instance changed) it’s added (if not present) to the instanceStore and the server’s response data updates this instance;
- when a define map’s prop is declared as that Type, the new instance(s) are returned from the instanceStore based in the unique identifier match;
- when a instance is fetched from the server using Type.get({id: “A”}), the instance is first returned from the instanceStore and if server’s response data returns an new/modified props the instance is updated;
I’ve done some reading on the can-connect’s docs/tests/code to understand what behaviors to use and how to configure them.
The superMap connection at jsbin relies on fall-through-cache and it matches part of the desired capabilities: a cached instance is returned immediately with the previously created data; request to server is still done; the changed data from the server response forces the instance to updateaccordingly.
The unfulfilled expectation is the cached instance to be different from the previously saved instance.
It seems that the cached data was used to create and returned a new instance.
The custom connection at glitch make use of the behaviors that somehow seem to interact with the instanceStore.
There’s no cache connection setup in order to evaluate if the instanceStore is being filled and accessed as expected.
Here, the instanceStore its just added with the response of the latest Type.get() and the new initialization doesn’t go to the instanceStore to look for a instance with the same iD.
Note: I didn’t put it in jsbin too because the can.all.js distribution doesn’t have the can-connect/can/map/map behavior exported.
To wrap up, my expectation is to setup a connection in such a way that there’s a instance(s) store synchronized with the configured caching layer (localStorage or memoryCache).
How to achieve this?
Thanks!