Custom proxy that re-routes to LocalStorage proxy and REST proxy internally
Custom proxy that re-routes to LocalStorage proxy and REST proxy internally
My goal is to use LocalStorage as a cache and offline storage, and to use REST proxy as the online source. When data is fetched from the REST proxy, a copy is sent to the LocalStorage proxy.
Where is the best implementation point you would suggest?
Option 1: Implement a BaseModel with CRUD methods that does the routing.
Option 2: Implement a custom Store that does the routing.
Option 3: Implement a custom Proxy that does the routing.
I'm attempting Option 3 and extending from Proxy, but got an exception with 'Uncaught TypeError: Cannot call method 'getIdProperty' of null'. I guess it's related to the Model being null. Should I extend from DirectProxy instead? Or should I go with alternative options?
I just made some progress. I resolved the exception by assigning model manually to the REST proxy, the LocalStorage proxy, and my custom Auto proxy.
Before, the model did not need to be assigned to proxy explicitly. By looking at your source code, I found it was automatically assigned when creating the store. Since now my store binds to the custom Auto proxy, I have to manually assign the model to the REST proxy and the LocalStorage proxy to eliminate the exception.
Am I on the right track? Any hint or sample implementation that you could provide? This requirement does not look to me as something too unusual. Thanks.