can-connect icon indicating copy to clipboard operation
can-connect copied to clipboard

localStorage should add every instance to the universal set

Open imaustink opened this issue 7 years ago • 5 comments

When trying to use can-connect as an interface for localStorage only, no HTTP calls, .getAll({}) results in {message: "no data", error: 404}.

This is the connection behavior I am using:

Todo.connection = connect([
  require('can-connect/data/localstorage-cache/localstorage-cache'),
  require('can-connect/constructor/constructor'),
  require('can-connect/can/map/map')
],{
  Map: Todo,
  List: Todo.List,
  name: 'todo',
  algebra: Todo.algebra
});

This branch contains my work-in-progress where I am using this behavior: https://github.com/canjs/todomvc/tree/update-canjs-example-to-3.x

cc: @justinbmeyer

imaustink avatar Aug 02 '17 03:08 imaustink

you probably just need to include the data/callbacks & data/callbacks-cache behaviors

nlundquist avatar Aug 15 '17 22:08 nlundquist

oh and localstorage-cache should be on a separate connection that is passed to the Todo.connection as the 'cacheConnection' property, e.g: https://canjs.com/doc/can-connect/data/localstorage-cache/localstorage-cache.html#Use

nlundquist avatar Aug 15 '17 22:08 nlundquist

@imaustink I assigned this to you to figure out if @nlundquist’s recommendations cover your needs, or if this is a bug that needs to be fixed.

chasenlehara avatar Aug 28 '17 22:08 chasenlehara

@chasenlehara I had a good talk with @nlundquist about this. As it stands, can-connect won't work with only localStorage. Nils explained that adding this functionality would fundamentally change how caching behaves and suggested discussing this further with @justinbmeyer to confirm this is the right plan of action. Between other priorities and the retreat, I have not been able to discuss this with Justin yet. I am hoping we'll be able to talk it over this week.

imaustink avatar Aug 28 '17 23:08 imaustink

@justinbmeyer the problem is that the localstorage behavior currently can’t return lists that weren’t calculated by some backend and then cached in it - to work as a data source it will need to be able to calculate lists itself. The question is how that should be implemented.

imaustink avatar Aug 31 '17 04:08 imaustink